1.ajax cross-domain pass value is the type of postback required JSONP
$.ajax ({
URL: "http://...",
type: ' Get ',
dataType: ' JSONP ',//js cross-domain value
success:function (data) {
}
});
DataType
Type: String
The type of data expected to be returned by the server. If not specified, JQuery will automatically intelligently judge against HTTP packet mime information, such as XML MIME types being recognized as XML. In 1.4, JSON generates a JavaScript object, and script executes it. The data returned by the server side will then be based on
After this value is parsed, it is passed to the callback function. Available values:
"XML": Returns an XML document that can be processed with jQuery.
HTML: Returns plain text HTML information, and the included script tag executes when the DOM is inserted.
Script: Returns the plain text JavaScript code. Results are not automatically cached. Unless the "cache" parameter is set. Note: On remote requests (not in the same domain), all POST requests are converted to get requests. (because it will be loaded using the DOM's script tag)
"JSON": Returns JSON data.
"JSONP": Jsonp format. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? To the correct function name to execute the callback function.
2.ajax Demo sample with PHP to get the value
$ (function () {
var my_data= "foreground variable";
My_data=escape (My_data) + "";//encode to prevent Chinese characters from garbled
$.ajax ({
URL: "ajax_php.php",
Type: "POST",
data:{trans_ Data:my_data},
//datatype: "JSON",
error:function () {
alert (' Error loading XML document ');
success:function (data,status) {//If invoking PHP Success
alert (unescape (data);//decoding, displaying kanji
}
}
);
PHP code
Copy Code code as follows:
$backValue =$_post[' Trans_data ']; echo $backValue. " + Backstage Return ";
Data conversion processing for 3.php JSON
Json_decode (String $json [, bool $assoc]); Accepts a JSON-formatted string and converts it to a PHP variable
Json_decode ($data, true);
JSON string format to be decoded by JSON. Assoc When this argument is TRUE, the array is returned instead of object.
Json_encode (mixed $value [, int $options = 0]) returns the JSON form of value values
Json_encode ($a)
The above probably to share three Ajax small problems, very common, hope to help everyone!