Source: http://api.jquery.com/jquery.ajax/
XML: Returns an xml document that can be processed via Jquery. the return must be treated as XML nodes
$.ajax({
url : "xml.xml",
dataType : "xml",
success : function(xml){
$(xml).find('item').each(function(){
var titulo = $(this).find('title').text();
console.log(titulo);
});
}
});
JSON: Evaluates the response as JSON and returns a javascript object
$.ajax({
url : "json.php",
dataType : "json",
success : function(data){
for($i=0; $i < data.length; $i++)
console.log(data[$i])
}
});
JSONP: Request very similar to JSON, except that it is possible to make calls through different domains, with an additional parameter called callback.
//json.php
{ foo: 'bar' }
--
//jsonp.php
meucallback({ foo: 'bar' })
--
$.ajax({
url : "www.outrosite.com/jsonp.php",
dataType : "jsonp",
jsonpCallback : "meucallback"
});
--
function meucallback(obj)
{
console.log(obj);
}
SCRIPT: Load an external script in string format
//externo.js
alert("OLA")
--
$.ajax({
url : "externo.js",
dataType : "script",
success : function(scriptString){
eval(scriptString); //executa o script retornado
}
});
The answers below are decent, but no one answered: ... How this influences the execution of the script and return of the result ...
– Andrei Coelho