Ajax with Jquery
Following is simple example code can be use to send the ajax requests using JQuery.
Sending Ajax request with JQuery is much more easier than can apply more user friendly messages to user
Sending Ajax request with JQuery is much more easier than can apply more user friendly messages to user
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
http://docs.jquery.com/Ajax/jQuery.ajax
Note : In IE browsers it convert and process the XML response string as Text prevent that
can use as following
$.ajax({
url: "data.xml",
dataType: ($.browser.msie) ? "text" : "xml",
success: function(data){
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
// Returned data available in object "xml"
}
There are much more options can be specified in ajax request.
$.ajax({
url: 'document.xml',
type: 'GET',
dataType: 'xml',
timeout: 1000,
error: function(){
alert('Error loading XML document');
},
success: function(xml){
// do something with xml
}
});
});
Response XML can be process as follows and populate the required stuff
success: function(xml){
$(xml).find('item').each(function(){
var item_text = $(this).text();
$('')
.html(item_text)
.appendTo('ol');
});
}
Comments