jquery ajax function
satya - Sat Apr 28 2012 07:09:44 GMT-0400 (Eastern Daylight Time)
document reference for $.ajax
satya - Sat Apr 28 2012 07:12:01 GMT-0400 (Eastern Daylight Time)
How do I get a server side html into a div
$.ajax({
url: "test.html",
cache: false
}).done(function( html ) {
$("#results").append(html);
});
Notice the cache setting
satya - Sat Apr 28 2012 07:36:07 GMT-0400 (Eastern Daylight Time)
jqXHR ref at Jquery
satya - Sat Apr 28 2012 07:37:14 GMT-0400 (Eastern Daylight Time)
Here is the real link indicating this is the object returned by the $.ajax function
Here is the real link indicating this is the object returned by the $.ajax function
satya - Fri Oct 05 2012 18:10:01 GMT-0400 (Eastern Daylight Time)
calling ajax from a local html file?
calling ajax from a local html file?
satya - Fri Oct 05 2012 18:26:57 GMT-0400 (Eastern Daylight Time)
enable jquery logging
enable jquery logging
satya - Fri Oct 05 2012 19:28:47 GMT-0400 (Eastern Daylight Time)
what ever I do I am not able to make $.ajax work from a local file to a website
what ever I do I am not able to make $.ajax work from a local file to a website
satya - Fri Oct 05 2012 19:33:12 GMT-0400 (Eastern Daylight Time)
It also seem to be temperamental about the dataType variable
It also seem to be temperamental about the dataType variable
satya - Fri Oct 05 2012 20:09:05 GMT-0400 (Eastern Daylight Time)
On ie9 the following seem to work using all local files
<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>
satya - Fri Oct 05 2012 20:11:17 GMT-0400 (Eastern Daylight Time)
Couple of notes
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.
satya - Sun Oct 07 2012 08:21:47 GMT-0400 (Eastern Daylight Time)
Here is the documentation on success
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.
satya - Sun Oct 07 2012 09:11:52 GMT-0400 (Eastern Daylight Time)
Here is a way to use context and possibly multiple calls to the backend
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