Home > Backend Development > PHP Tutorial > javascript - ajax does not go to success, only error, and the request status code is 200.

javascript - ajax does not go to success, only error, and the request status code is 200.

WBOY
Release: 2016-09-11 11:34:08
Original
1341 people have browsed it

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:

javascript - ajax does not go to success, only error, and the request status code is 200.

The backend code is as follows:

javascript - ajax does not go to success, only error, and the request status code is 200.

javascript - ajax does not go to success, only error, and the request status code is 200.

Reply content:

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:

javascript - ajax does not go to success, only error, and the request status code is 200.

The backend code is as follows:

javascript - ajax does not go to success, only error, and the request status code is 200.

javascript - ajax does not go to success, only error, and the request status code is 200.

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>
Copy after login

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>
Copy after login

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>
Copy after login

update

javascript - ajax does not go to success, only error, and the request status code is 200.

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?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template