阿贾克斯投掷的错误与正确的结果正确、错误、结果、阿贾克斯

2023-09-11 01:29:37 作者:◢看不穿◤繁华世间ゐ情

我有以下功能:

side= 'car';

    var request_checkUrl = '/antibot/antibot_data?script=' + side;

 $.ajax({
    url: request_checkUrl,
    dataType: 'application/json',
    complete: function(data){
       alert("running..");
    },
    success: function(data){
        alert("success");
    },
    error: function(data) {
        alert("ERROR");
        console.log(data);
    }

})

的结果是: 用错误的盒子,并运行。这也显示了这个在控制台日志:

the results are: the box with ERROR, and the running. it also shows this in the console log:

里边反反应是正确的。但是,为什么这片code把我的错误信息,当它应该是成功的?

tthe response is correct. but, why does this piece of code throw me error message, when it should be success?

我也试过用GET,的getJSON,Ajax和数据类型的JSON,等等。但我得到了相同的结果。

I also tried with get, getjson, ajax with datatype json, etc.. but i get the same outcome.

我做错了什么在这里?

编辑:

下面是完整的响应:

{
    "status": 200,
    "data": {
        "text": "en TV",
        "images": [
            {
                "hash": "47a32df0c4b1f0b522e5faf35a46aacd95fe0ed4",
                "file": "ABImage_plane_1"
            },
            {
                "hash": "e11f83f4411364546329c8a8bf88da0dffd27029",
                "file": "ABImage_house_2"
            },
            {
                "hash": "93b4454ac09e7d7478fa2d25322e0e784370ea7a",
                "file": "ABImage_car_5"
            },
            {
                "hash": "36fac21a830b922edb507487d833556aeb9688f7",
                "file": "ABImage_clock_4"
            },
            {
                "hash": "cd1df47e052a5d0d50dab61b3e716339be0c6e68",
                "file": "ABImage_TV_3"
            },
            {
                "hash": "59e7f70b7874a500e576e25077adf254c52f5ee8",
                "file": "ABImage_train_4"
            }
        ]
    }
}

EDIT2:

这是使用即时通讯服务器的功能双面PHP

this is the function that im using server sided PHP

echo $this->framework->ajaxJSONResponse(200, $data);

 function ajaxJSONResponse($status, $data)    {
        header('Content-type: application/json');
        $response             = array();
        $response['status']   = $status;
        $response['data']     = $data;
        return json_encode($response);
    }

编辑: 使用jQuery 2.1.3 IM

im using jquery 2.1.3

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

编辑: 我也尝试过:

I also tried:

$.ajax({
    url: request_checkUrl,
    type: "GET",
    dataType: "json", // "xml", "json"
    success: function (data) {

        alert("success");
        alert(data);

    },
    error: function (jqXHR, textStatus, ex) {
        alert(textStatus + "," + ex + "," + jqXHR.responseText);
    }
});

与输出误差:

with the output error:

再次更新:

我试图验证网址有: http://www.freeformatter.com/json-validator.html

i tried to validate url with: http://www.freeformatter.com/json-validator.html

和有:

The JSON input is NOT valid according to RFC 4627 (JSON specification). Unexpected token {"status":200,"data":{"text":"en TV","images":[{"hash":"47a32df0c4b1f0b522e5faf35a46aacd95fe0ed4","file":"ABImage_plane_1"},...

但是,如果我能:

but if i enable:

接受不带引号的名称

我得到:

The JSON input is valid according to RFC 4627 (JSON specfication).

我怎样才能使这项工作对我的要求吗?

how can i make this work on my request too?

推荐答案

以下的答案只是试图帮助一个可能的解决方案。

The following answer just try to help with a possible solution.

尽量解决您的code到这样的事情:

Try to fix your code to something like this:

var side = 'car';
var request_checkUrl = '/antibot/antibot_data?script=' + side;

$.ajax({
    url: request_checkUrl,
    type: "GET",
    dataType: 'json',
    beforeSend: function () {
        document.title = "Running...";
    },
    success: function (data) {
        document.title = "Success.";
        alert("success");
    },
    error: function (data) {
        alert("ERROR");
        console.log(data);
    }
});

让我知道,如果这个工程。

Let me know if this works.

更新:

在你最近更新,你得到了一个无效的JSON。自PHP你需要打印一个有效的JSON,始终。您可以使用此链接以验证您的JSON输出: http://pro.jsonlint.com

In your last update, you are getting an invalid json. Since PHP you need to print a valid json, always. You might use this link to validate your json output: http://pro.jsonlint.com.

parsererror,SintaxError:意外标记:这意味着,你已经错了的东西在PHP中code

parsererror, SintaxError: Unexpected token: It means, you've something wrong in php code.