PHP returns data in formats such as Json,xml,jsonp
Return JSON data:
Header (' Content-type:application/json; Charset=utf-8 '); $arr Array (' A ' =>1, ' B ' =>2); Exit (Json_encode ($data));
Note: If you do not add the header directly output Json_encode value, the return is the string is not an object, JS there will need to first eval (' (' +data+ ') ') into the object, in the value
return XML data:
Header (' Content-type:text/xml; Charset=utf-8 '); Exit ($xml);
Return JSONP data:
$arr Array (' A ' =>1, ' B ' =>2, ' C ' =>3); $json = Json_encode ($arr); $callback $_get [' Callback ']; Exit ($callback. " ($json) "); // Note that callback is the parameter name that JS passes over.
By the way thinkphp how to return various data:
$this->ajaxreturn (Json_encode ($arr), ' json ');
$this->ajaxreturn (Json_encode ($arr), ' JSONP ');
$this->ajaxreturn (Json_encode ($arr), ' XML ');
PHP returns data in formats such as JSON,XML,JSONP