简体   繁体   English

在jsonp中使用jsonp和get请求时,请求的JSON解析失败

[英]Requested JSON parse failed When using jsonp and get request in jquery

i'm trying to use cart.com API and retrieve json file using JQuery $.ajax like this 我正在尝试使用cart.com API并使用JQuery $ .ajax这样检索json文件

$(function(){
  $.ajax({

            type: 'GET',
            dataType: 'jsonp',
            contentType: 'application/json; charset=utf-8',
            crossDomain: 'true',
            async: false,
            jsonp: "callback",
            url: 'http://fadi%40example.com:Gu86P606iU3026G3587rT15S4q8i31D4@demos.cs-cart.com/54bbdcef36bac/api.php?_d=Settings&ajax_custom=1',
            complete: function(result){

            console.log(result);  
        },
          success: function(data) {
            var data1 = $.parseJSON(data);
            console.log(data1);   
          },
           error: function(jqXHR, exception) {
                        if (jqXHR.status === 0) {
                            alert('Not connect.\n Verify Network.');
                        } else if (jqXHR.status == 404) {
                            alert('Requested page not found. [404]');
                        } else if (jqXHR.status == 500) {
                            alert('Internal Server Error [500].');
                        } else if (exception === 'parsererror') {
                            alert('Requested JSON parse failed.');
                        } else if (exception === 'timeout') {
                            alert('Time out error.');
                        } else if (exception === 'abort') {
                            alert('Ajax request aborted.');
                        } else {
                            alert('Uncaught Error.\n' + jqXHR.responseText);
                        }
                    }
        });

    });

so when i run it tell me Requested JSON parse failed and in the response the data comes as js file how can i get this data from the js 因此,当我运行它时,告诉我Requested JSON parse failed并且响应中的数据以js文件的形式出现,我如何从js获取此数据

json文件作为js

please any help please i have this problem from three days till now and i can't get the data from the js file i will be most thankful for any help. 请任何帮助请从三天到现在我有这个问题,我无法从js文件中获取数据,我将非常感谢您的帮助。

Did you set the Content Type to "application/json" on server side? 您是否在服务器端将内容类型设置为“ application / json”? Missing this step can cause problems like this. 缺少此步骤可能会导致类似的问题。 I'm asking this because browsers used to display the json files in a most sophisticated way and your Preview is not really well-formatted. 我之所以这样问,是因为浏览器曾经以最复杂的方式显示json文件,而您的Preview的格式却不是很好。

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

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