AJAX using Visual Basic

by pau on February 18, 2009 · 1 comment

in Visual basic

Ajax or Asynchronous JavaScript and XML is a web development technique that used XMLHttpRequest object to provide us a way to communicate with a server after a web page has loaded.

What Ajax or XMLHttpRequest object can do?

  • Update a web page with new data without reloading the page
  • Request data from a server after the page has loaded
  • Receive data from a server after the page has loaded
  • Send data to a server in the background

Working of AJAX with VB

Here’s how to used XMLHttpRequest object in visual basic to get data directly from web server.

Outside variable declaration

public vbAjax As Object

Build public function

public function AjaxRequest(url as string)
    'set object
    Set vbAjax = CreateObject("Microsoft.XMLHTTP")

    If Not vbAjax Is Nothing Then
        vbAjax.open "GET", url, False
        vbAjax.send (Null)
        '4 = "loaded"
        If vbAjax.readyState = 4 Then
            '200 = OK
            If vbAjax.Status = 200 Then
            'our code here...
            MsgBox "STATUS: " & vbAjax.Status & vbNewLine & vbNewLine & "STATUSTEXT: " & vbAjax.statusText & vbNewLine & vbNewLine & vbAjax.responseText
            Else
                MsgBox "Problem retrieving XML data"
            End If
        Else
            MsgBox "Not Ready"
        End If
    End If

    Set vbAjax = Nothing
end function

calling the function

call AjaxRequest("http://www.w3schools.com/XML/note.xml")

RESOURCES :

Related Posts

{ 1 trackback }

Working AJAX in visual basic | pauxcore
02.19.09 at 12:59 am

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>