jQuery ajax method Summary

 

Commonly used ajax use:

$ .Ajax ({
     type : "POST / GET" ,
     URL : "URL" ,
     the async : to true / fasle,
     Data : {
       value_name : value },    Success: function (Data, Status, ajaxclass) { // return data processing },    error: function () { method upon failure // Ajax }})
    

        
    

        
    

Detailed description:

  1. type: type by value, are divided into two kinds of post and get
  2. url: address by value
  3. async: whether asynchronous, default true if the property does not write. (Asynchronous multi-threading, synchronization is single threaded)
  4. data: by value, a single value can be written directly, e.g. name, an interface name can receive this value, multiple values ​​json format, traditional values ​​{name: value, value-passing name: value, ......} form
  5. success: When the callback function ajax run successfully, a parameter: data (any name) is the return value of two parameters: status (any name) Returns ajax execution state, where returns Success, three parameters: ajaxclass (any name) returns the current ajax some data objects.
  6. error: When the ajax callback function fails, commonly used as an error prompt.

Complex usage parameters:

  1. dataType: expected data type returned by the server.
  2. processData: In general, the data passed in through the option data, if an object (if not technically a string), the processing will be transformed into a query string bar, to match the default content type "application / x-www -form-urlencoded ". If a DOM tree or other information not want to convert the transmission, is set to false. The default is to true . This property is used when the data transfer for FormData attribute value must be false.
  3. contentType: Default "application / x-www-form -urlencoded". Sending information to the server when the content encoding class type. This property is used when the data transfer for FormData attribute value must be false. Related Expansion:If you do not add this parameter, unpredictable errors occur! For example, some of the added system security controls, without this parameter, will direct error 403, the system thinks your request is attacking the system. Ajax ② When uploading files, we check to see Request headers will find content-Type This parameter is multipart / form-data later there will be a boundary then followed by a string of random string, the argument before us is not new, this is the form forms must upload a file of parameters when we upload the file, the system will automatically generate a bunch of random string, the purpose is to prevent the file appears delimiter causing the server can not resolve the beginning of the file correctly. Having said that, we found that JQuery ajax () method we make ontentType = false, this is not a conflict yet? This is of course not, because when we look at this time of the Request headers, will find that there are still delimiter. This is because when we set up in the form tag enctype = "multipart / form-data" , such a request contentType will default to multipart / form-data. And we set to false ajax contentType in order to avoid JQuery its operation, thus losing the delimiter, the server can not parse the file correctly.


 

Guess you like

Origin www.cnblogs.com/huixincode/p/11590768.html