简体   繁体   English

Ajax数据没有成功

[英]ajax data doesn't fall into success

I am new to Ajax and trying to fill a table with the data coming from a server. 我是Ajax的新手,正在尝试用来自服务器的数据填充表。

Here is my GET function: 这是我的GET函数:

<script type = "text/javascript" charset="utf-8">
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "myURL",
            dataType: "jsonp",
            success: function (response) {
                debugger;
                var trHTML = '';
                $.each(response, function (i, v) {
                    // append to table
                    trHTML += '<tr><td>' + v.Ticker+
                              '</td><td>' + v.Close+
                              '</td><td>' + v.percentage+
                              '</td></tr>';
                });
                $("#art").append(trHTML);
            },
            error: function (e) {
                debugger;
                console.log(e)
                alert(e + " Error");
            }
        });
    });
</script>

Incoming data falls into Error every single time and it is like: 传入数据每次都会陷入错误 ,就像:

e = Object {readyState: 4, responseText: "{"Ticker":"akbnk.is","Close":6.74,"percentage":-1…s","Close":1.54,"percentage":9.2198581560283781}]", s

I can see this much on Chrome. 我可以在Chrome上看到很多。 Does anybody know how to fix this? 有人知道如何解决此问题吗?

You said: 你说:

 dataType: "jsonp", 

Your data says: 您的数据显示:

 {"Ticker":"akbnk.is","C 

Your data appears to be JSON. 您的数据似乎是JSON。 JSON is not JSONP, so it errors. JSON不是JSONP,因此会出错。

Either say "json" or change the server to return JSONP . "json"或更改服务器以返回JSONP

Your response not JSONP so when you trying to use ajax request with dataType: "jsonp", response must be of same JSONP . 您的响应不是JSONP因此,当您尝试将dataType: "jsonp",使用ajax请求时dataType: "jsonp",响应必须为JSONP If it will not then it doesn't come in success callback. 如果不会,则不会成功回调。

So either remove dataType: "jsonp" or change dataType: "json" or change your response to JSONP . 因此,请删除dataType: "jsonp"或更改dataType: "json"或将您的响应更改为JSONP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM