Home > Article > Web Front-end > jquery cross-domain request example sharing (jquery sends ajax request)_jquery
getJSON is commonly used in jQuery to call and obtain the remote JSON string, convert it into a JSON object, and if successful, execute the callback function. The prototype is as follows:
jQuery.getJSON( url, [data], [callback] ) loads JSON data across domains.
url: the address to send the request
data: (optional) key/value parameters to be sent
callback: (optional) callback function when loading is successful
is mainly used for the client to obtain the server JSON data. Simple example:
Server script, return JSON data:
Note two points: First: Before returning to the client, use the PHP function json_encode to encode the returned data. Second: echo is used to return to the client, not return.
The following is the core client code: