jquery provides Ajax functions, in the course of use, because of the parameters of the understanding, resulting in a lot of errors, now summarized as follows, so that when the room temperature solid, do not make the same mistake.
1. The AJAX request format I used in my project is as follows:
1 $.ajax ({2 URL:3 Data:4 ContentType:5 DataType:6 Type:7Completefunction(res, textstatus, jqxhr) {8 if(Textstatus! = ' Success '){9 Ten } One }, AErrorfunction(){ - - }, theSuccessfunction(res) { - - } -});
What is the meaning of the 3 type that appears here?
The first contenttype, excerpts from a stackoverflow on the answer:
ContentType (default: ' application/x-www-form-urlencoded; Charset=utf-8 ')
Type:string
When you sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; Charset=utf-8 ", which is fine for the most cases. If you explicitly pass in a content-type to $.ajax () and then it's ll always be sent to the server (even if no data is Sent). If No CharSet is specified, data would be transmitted to the server using the server ' s default CharSet; You must decode this appropriately on the server side.
This parameter is set to specify how the server parses the parameter, and the default is application/x-www-form-urlencoded; Charset=utf-8, can also be clearly pointed out in the request, the other common language JSON object parameters, ContentType is also set to "Application/json".
The second datatype, the same excerpt from StackOverflow's answer:
DataType (default:intelligent Guess (XML, JSON, script, or HTML))
Type:string
The type of data that you ' re expectingback from the server. If None is specified, JQuery would try to infer it based on the MIME type of the response (an XML MIME type would yield XML, In 1.4 JSON would yield a JavaScript object, in 1.4 script would execute the script, and anything else would be returned as A string).
This parameter specifies that the data type that we want the server to return, for example, may not be specified, and the server will judge for itself.
The third type: is what we request to send the data. There are two kinds of "GET" and "POST".
2, the server returned a 400 error: The bad request, it is likely that the requested parameter is wrong, for example, the need to send two parameters, but only one sent ; or server-side settings accept data type and actual transmission inconsistency (For example, I specify contenttype: ' application/x-www-form-urlencoded ', but the server needs contenttype: ' application/x-www-form-urlencoded ; Charset=utf-8 '). Such errors from the console can not see the specific reasons, you need to check the parameters of what is wrong.
[JQuery] A summary of the problems in AJAX use process