亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Cross-domain, is my jsonp method correct? Why do I keep getting errors?
高洛峰
高洛峰 2017-07-05 10:41:03
0
6
812


The path of this ajax request, right?

Is my cross-domain method correct? Why does the console keep reporting errors

高洛峰
高洛峰

擁有18年軟件開(kāi)發(fā)和IT教學(xué)經(jīng)驗(yàn)。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項(xiàng)目經(jīng)理、高級(jí)軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...

reply all(6)
迷茫

Uncaught SyntaxError: Unexpected token: An error like this is caused by the returned json data not being enclosed in "(" and ")" parentheses or not adding a callback value in front.

黃舟

There is a problem with the server program, js execution error

我想大聲告訴你

Set the jsonp parameters, and the data returned by the background needs to be wrapped in the jsonp variable you passed
Front-end:

$.ajax({
    url: 'xx',
    dataType: 'jsonp',
    jsonp: 'callback',
    ....
});

Backend
callback (returned data)

小葫蘆

Add a callback parameter to url: jsoncallback=?, the question mark program will automatically generate the corresponding parameters

The backend program accepts this parameter and wraps the returned data in this callback function

eg:
PHP后端寫法

$jsoncallback = $_GET['jsoncallback'];

$result = json_encode($data);

echo  $jsoncallback."(".$result.")";//后端要以這種格式返回?cái)?shù)據(jù)才能實(shí)現(xiàn)跨域
exit;

Your return value is not wrapped in a callback function

洪濤

jsonp should not be introduced by src in js, and then called callback() in js

滿天的星座

For jsonp in JQ, do you need to add a callback= to the query string? Field

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template