The path of this ajax request, right?
Is my cross-domain method correct? Why does the console keep reporting errors
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
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:
jsonp
$.ajax({ url: 'xx', dataType: 'jsonp', jsonp: 'callback', .... });
Backendcallback (returned data)
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.")";//后端要以这种格式返回数据才能实现跨域 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
callback()
For jsonp in JQ, do you need to add a callback= to the query string? Field
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 thejsonp
variable you passedFront-end:
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
Your return value is not wrapped in a callback function
jsonp should not be introduced by src in js, and then called
callback()
in jsFor jsonp in JQ, do you need to add a callback= to the query string? Field