ArticleDirectory
- Same domain:
- Cross-origin:
1. Invalid label Error
There are two scenarios:
Same domain:
Use eval to translate the returned JSON into response
VaR JSON = eval ('+ myjson + ')');
Cross-origin:
First, the URL has callback =?
Second, we also need to output the callback value during the output.
$ Dal = $ _ Get ['callback'];
Echo $ Dal. '('. json_encode ($ retdata1 ).')';
Note: When $ dal is connected to a JSON array, the JSON array must contain brackets.
2. Output JSON data with HTML tags
If you want to include the HTML Tag value in JSON data, it is the cause of failure during execution:
Because/is processed as \/, the browser determines that the tag is incomplete and the tag is automatically filled up, resulting in additional tags.
Solution:
$ JSON = json_encode ($ result );
$ Myjson = strtr ($ JSON, array ('<' => '\ u003c', ">" => '\ u003e '));
Echo $ myjson;
If phpversion> 5.3.0, You can echo json_encode ($ A, json_hex_tag );