0

i'm trying to use cart.com API and retrieve json file using JQuery $.ajax like this

$(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

json file as 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.

Fadi
  • 2,320
  • 8
  • 38
  • 77
  • You are almost there to get data from json now. pass key and get appropriate value with in json objects – Ajay Takur Jan 20 '15 at 16:21
  • what data you want from json ? – Ajay Takur Jan 20 '15 at 16:23
  • any thing now just for test any thing pleas help – Fadi Jan 20 '15 at 16:24
  • Are you sure that the service you're calling supports JSONP? I don't see any evidence that the cart.com API does. The response you're getting is just JSON. – JLRishe Jan 20 '15 at 16:27
  • no i dont know if they supports JSONP – Fadi Jan 20 '15 at 16:33
  • console.log("NAME::"+data1.name+"EDITION TYPE::"+data1.edition_type); copy this in success function and run once. – Ajay Takur Jan 20 '15 at 16:34
  • They probably don't support JSONP. You should change your dataType to 'JSON', but then your browser will probably say that it doesn't support cross-domain requests. You'll have to do the requests on your own server, I'm afraid. – Terrabythia Jan 20 '15 at 16:35

1 Answers1

0

Did you set the Content Type to "application/json" on server side? 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.

szpetip
  • 333
  • 6
  • 12
  • no i'm trying to do this from the client side only how / where i set the Content Type to "application/json" in the server – Fadi Jan 20 '15 at 16:29
  • As I see you use PHP on server side. When you wrote the server-side code, check this: http://stackoverflow.com/questions/4064444/returning-json-from-a-php-script Otherwise you can check the Content Type on your browser, just google it, "show content type browser yourbrowser". – szpetip Jan 20 '15 at 16:35