Jquery provides convenient Ajax application. I will summarize some of my experiences below:
$. Get () and $. Post () methods are basically the same, so only $. Post () is used!
Scenario 1: $. Post ("url", function); The returned data is not processed, so it is not in JSON format!
Scenario 2: $. Post ("url", function, "JSON"); although the returned data is specified in JSON format, it is not actually!
Case 3: $. Post ("url", {}, function); the input parameter is null and the returned data format is not specified, so it is not in JSON format!
Scenario 4: $. Post ("url", {}, function, "JSON"); The JSON format data is returned correctly!
Key point: to process the returned data in JSON format, you must input a parameter (the parameter is written as {} if it is null) and specify the return type as "JSON "!
$. Ajax ({
URL: "url ",
Datatype: "JSON ",
Type: "Get"
Success: Function
})
Key Point: To specify datatype as "JSON", both get and post methods will get JSON data. However, we recommend that you add data to the above two methods to ensure consistency:.
$. Getjson ("url", function)
Key Point: Get data in JSON format. It is convenient to write $. Get!