Source: link
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 call 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: Loads 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
}
});