Directly executing the error method prompts an error - ajax jsonp has not been used before, and the understanding of it is similar to that of ordinary ajax requests, and there is no in-depth understanding of it; this error occurs, after several debugging (check the background code and js part Property settings) still doesn't work, which makes me feel very surprised and puzzled. Therefore, I decided to carefully study the use of ajax jsonp, and share the learning experience of the final successful test with everyone!
First, post the code that can be successfully executed:
(page part)
Ajax request parameter description:
dataType String
The data type expected to be returned by the server. If not specified, jQuery will automatically make intelligent judgments based on the MIME information of the HTTP package. For example, the XML MIME type is recognized as XML. In 1.4, JSON will generate a JavaScript object, and script will execute the script. The data returned by the server will then be parsed based on this value and passed to the callback function. Available values:
"xml": Returns an XML document that can be processed with jQuery.
"html": Returns plain text HTML information; the included script tag will be executed when inserted into the dom.
"script": Returns plain text JavaScript code. Results are not cached automatically. Unless the "cache" parameter is set. '''Note:''''When making remote requests (not under the same domain), all POST requests will be converted into GET requests. (Because the DOM script tag will be used to load)
"json": Returns JSON data.
"jsonp": JSONP format. When calling a function using JSONP format, such as "myurl?callback=?" jQuery will automatically replace ? with the correct function name to execute the callback function.
"text": Returns a plain text string
jsonp String
Rewrites the name of the callback function in a jsonp request. This value is used to replace the "callback" part of the URL parameter in a GET or POST request such as "callback=?". For example, {jsonp:'onJsonPLoad'} will cause "onJsonPLoad=?" to be passed to the server.
jsonpCallback String
Specify a callback function name for jsonp request. This value will be used instead of the random function name automatically generated by jQuery. This is mainly used to allow jQuery to generate unique function names so that it is easier to manage requests and provide callback functions and error handling. You can also specify this callback function name when you want the browser to cache GET requests.
The main difference between ajax jsonp and ordinary ajax requests is the processing of request response results. The response result shown in the above code is:
success_jsonpCallback([ { name: "John"} ] ); ——In fact, it is to call the jsonp callback function success_jsonpCallback and pass the string or json to be responded to here Method (as parameter value), its underlying implementation, a rough guess should be: