[<<][webdev][>>][..]
Thu Mar 25 13:28:03 CET 2010

Ajax

In order to make Ajax work in firefox, all the files need to come from
the same domain.  Apparently this doesn't work with file:/// urls.

A quick workaround is to set up a web server using:

    cd <dir>
    python -m SimpleHTTPServer

which makes the directory available on port 8000.

A basic asynchronous request looks like[1]:

  $.ajax({ 
      url: "consumption.json", 
      dataType: "json",
      success: function(data){
          z.json = data;
      }});


This returns an XMLHttpRequest object, which is not very useful.  In
order to get to the data you need to set a callback.  Here we just
store it in a global variable.

For JSON data this wrapper is defined: 

  $.getJSON("consumption.json", function(data) { 
      ...
  }))


What about XML?  Same story.  The data passed to the callback is a DOM
representation of an XML document. 

  $.ajax({ 
      url: "console.xml", 
      dataType: "xml",
      success: function(data){
          z.xml = data;
      }});


[1] http://api.jquery.com/jQuery.getJSON/




[Reply][About]
[<<][webdev][>>][..]