AJAX is a technique for exchanging data with the server, and it can be used to update part of the page in the context of the entire page.
The following table lists all the JQuery AJAX methods:
jquery Ajax in the Web application development is very common, it mainly includes ajax,get,post,load,getscript and so on these several common no refresh operation method, next through this article to introduce jquery Ajax upload file processing mode.
Formdata objects
XMLHttpRequest Level 2 Adds a new interface formdata. Using the Formdata object, we can simulate a series of form controls using JavaScript with some key-value pairs, and we can also use the XMLHttpRequest send () method to commit the "form" asynchronously. The great advantage of using formdata is that we can upload a binary file asynchronously compared to ordinary Ajax.
Newer versions of all major browsers already support this object, such as Chrome 7+, Firefox 4+, IE 10+, Opera 12+, Safari 5+. It was written with the original JS XMLHttpRequest.
XMLHttpRequest Way
Xhr.open ("POST", Uri, true);
Xhr.onreadystatechange = function () {
if (xhr.readystate = 4 && xhr.status =) {
//Handle response.< C4/>alert (Xhr.responsetext); Handle response.
}
};
Fd.append (' myFile ', file);
Initiate a multipart/form-data upload
xhr.send (FD);
In fact, jquery Ajax can also be supported, the key is set: ProcessData and ContentType.
Ajax Way
var formData = new FormData ();
var name = $ ("input"). Val ();
Formdata.append ("File", $ ("#upload") [0].files[0]);
Formdata.append ("name", name);
$.ajax ({
url:url,
type: ' POST ',
data:formdata,
//Tell jquery not to handle the sent data
Processdata:false,
//Tell jquery not to set Content-type request header
Contenttype:false,
beforesend:function () {
Console.log (" In progress, please wait ");
success:function (responsestr) {
if (responsestr.status===0) {
Console.log (Success) +RESPONSESTR);
} else{
Console.log ("failed");
}
,
error:function (responsestr) {
console.log ("error");
}
});