| http://www.wikiwand.com/en/Ajax_(programming) |
Para realizar este método, lo puedes hacer tomando nota de lo siguiente:
- Haciendo uso de un framework
- Codificándolo por tus propios medios
Sinceramente, y no es porque sea difícil, no es necesario codificar todo desde cero, es mejor hacer uso de algún framework pues llegarás a la misma Roma pero en menos tiempo.
Los diferentes framework que tenemos para esto son:
- jQuery
Para hacer ajax con jQuery, haz lo siguiente:
$.ajax({ url: "http://fiddle.jshell.net/favicon.png", beforeSend: function( xhr ) { xhr.overrideMimeType( "text/plain; charset=x-user-defined" );}
}).done(function( data ) { if ( console && console.log ) { console.log( "Sample of data:", data.slice( 0, 100 ) ); }});
- Vanilla
Para usar ajax con Vanilla, debes usar:
var r = new XMLHttpRequest();r.open("POST", "path/to/api", true);r.onreadystatechange = function () { if (r.readyState != 4 || r.status != 200) return; alert("Success: " + r.responseText);};r.send("banana=yellow");
- MooTools
var myRequest = new Request({ url: 'image.jpg', onProgress: function(event, xhr){ var loaded = event.loaded, total = event.total; console.log(parseInt(loaded / total * 100, 10));}});myRequest.send();
0 comments:
Post a Comment