Javascript-ajax Live not go success, only go error, request status code is 200.

Source: Internet
Author: User

Solve, how to solve it? Another domain name walk is OK, but this domain name does not go, front-end code is as follows:

The backend code is as follows:

Reply content:

Solve, how to solve it? Another domain name walk is OK, but this domain name does not go, front-end code is as follows:

The backend code is as follows:

Interface didn't deal with callback, right?

There is no error in the notation, it is estimated that the server side returned is not a jsonp format, callback processing failed.
$.ajax The default jsonp callback parameter is ?callback=_XXXX to see if background processing and return are correct.

The value of the server return is wrong yes, you're returning a null value. Look, what if there {"result":"successful"} 's something like that?

Javascript: Adding

$.ajax({    ....    jsonp:'jsonp_callback',  <- 指定callback回调函数名    ....})

jquery uses Ajax get to request a /url/?callback=jsonp_callback URL
The JavaScript callback that will then be executed jsonp_callback(result)

function(){    return string;}

JavaScript receives a string-type output. is not JSON. It's not the JSON that die.

function (){    // 这里是callback还是jsonp_callback忘了。具体百度一下    return $_GET['callback']."(".json_encode($string).")";    // 实际返回并输出的将会是:  `jsonp_callback("string")`}

Update

Look at the words:
The AJAX request address ishttp://baidu.com
The actual request address ishttp://baidu.com/?callback=xxxxxxx&_=xxx&_=xxxx

Why not use numbers instead of returning content?

DataType does not match the return value, it is recommended to remove this parameter so that jquery automatically recognizes the return value.
Besides, it's not jsonp, is it?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.