jquery ajax function

document reference for $.ajax


$.ajax({
  url: "test.html",
  cache: false
}).done(function( html ) {
  $("#results").append(html);
});

Notice the cache setting

jqXHR

Search for: jqXHR

jqXHR ref at Jquery

Here is the real link indicating this is the object returned by the $.ajax function

calling ajax from a local html file?

Search for: calling ajax from a local html file?

enable jquery logging

Search for: enable jquery logging

what ever I do I am not able to make $.ajax work from a local file to a website

It also seem to be temperamental about the dataType variable


<html><head>
<script type="text/javascript" src="jquery.js">
</script>
<script type="text/javascript" src="xmltojson.js">
</script>
<script type="text/javascript" src="json2.js">
</script>
<script>
function getstuff()
{
    var someurl="test.txt";
    $.ajax({
      url: someurl,
      cache: false,
      dataType:"xml",
      failure: showReturn,
      success: showReturn
    });
}

function showReturn(data)
{
    alert("hello");
    var s = xmlToJson(data);
    alert(typeof JSON);
    alert(JSON.stringify(s));
    alert(s);
    alert(data);
}
</script>
</head>

<body onload="getstuff()">
<p>Hello
</body></html>

if I don't set the data type as "xml" then what gets passed to the success function is just a string. If the datatype is set to xml then what gets passed seemed to be some type of XML object, perhaps a DOM or an XHR

this doesn't work at all on chrome.

I have to have json2.js on ie9 to have it recognize JSON as an object.

success(data, textStatus, jqXHR) Function, Array

A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.


function getstuff()
{
    var context = new AkcWidget();
    context.getData();
}
function AkcWidget()
{
    this.dataUrl = "test.txt";
    this.templateUrl = "sampleTemplate.txt";
    this.data = {};
    this.template = "";
    this.getHtml = function()
    {
        alert( "hello I am done");
        alert(JSON.stringify(this.data));
        alert(this.template);
    }
    
    this.getTemplate = function()
    {
        alert("getTemplate called");
        alert(this.templateUrl);
        $.ajax({
          url: this.templateUrl,
          cache: false,
          dataType:"text",
          context: this,
          failure: showReturn,
          success: replyFromGetTemplate
        });        
    }
    this.getData = function()
    {
        $.ajax({
          url: this.dataUrl,
          cache: false,
          dataType:"xml",
          context: this,
          failure: showReturn,
          success: replyFromGetData
        });      
    }    
    function replyFromGetData(data)
    {
        alert("reply from get data");
        var s = xmlToJson(data);
        this.data=s;
        alert("showReturn complete");
        this.getTemplate();    
    }
    
    function replyFromGetTemplate(data)
    {
        alert("replyFromGetTemplate called");
        this.template=data;
        this.getHtml();
    }
    
}//end-of-AkcWidget