How to solve it? It is OK to move another domain name, but this domain name will not be moved. The front-end code is as follows:
The backend code is as follows:
How to solve it? It is OK to move another domain name, but this domain name will not be moved. The front-end code is as follows:
The backend code is as follows:
The interface doesn’t handle callbacks, right?
The writing is correct. It is estimated that the server returned something other than the jsonp
format, and the callback processing failed. The default
jsonpcallback parameter of
$.ajax is ?callback=_XXXX
. Check whether the background processing and return are correct.
The value returned by the server is wrong. You are returning a null value. It looks like if there is something like {"result":"successful"}
, try something like that?
Javascript: Add
<code class="javascript">$.ajax({ .... jsonp:'jsonp_callback', <- 指定callback回调函数名 .... })</code>
jQuery will use AJAX GET to request a /url/?callback=jsonp_callback
URL
and then execute the jsonp_callback(result)
JavaScript callback
<code class="php">function(){ return string; }</code>
What javascript receives will be a String type output. It's not JSON. If it’s not JSON, it’s DIE.
<code class="php">function (){ // 这里是callback还是jsonp_callback忘了。具体百度一下 return $_GET['callback']."(".json_encode($string).")"; // 实际返回并输出的将会是: `jsonp_callback("string")` }</code>
update
Look at the picture and talk:
The ajax request address is http://baidu.com
The actual request address is http://baidu.com/?callback=xxxxxxx&_=xxx&_=xxxx
Why not use numbers instead of returned content?
dataType does not match the return value. It is recommended to remove this parameter and let jquery automatically recognize the return value.
Also, this is not jsonp, right?