1
$(function(){
    $.ajax({
        url: 'http://xxx/',
        type: 'GET',
        crossDomain:true,
        cache:true,
        dataType:"script",
        success:function(data,textStatus,jqXHR){

            alert(data);
        }
    }); 
});

actually server is returning json object and in my firebug it is showing SyntaxError: invalid label

What can I do ?

1
  • 3
    "invalid label" has no relation with cross domain errors. Oct 5, 2012 at 6:46

3 Answers 3

1

If the server returns json, then you could not get the data even you set crossDomain:true.

If you want to crossDomain work, the server need to support JSONP, which is wrapping the json with a callback function.

2
  • 1
    Whith CORS headers, you may do JSON. You don't HAVE to use JSONP. But what OP's trying isn't clear. Oct 5, 2012 at 6:50
  • @dystroy Yep, but this is not supported by all the browsers, so there come to JSONP.
    – xdazz
    Oct 5, 2012 at 7:40
1

Try dataType : "json" instead of dataType:"script"

0

hey i got the solutions for it

$.ajax({ type : "GET", url : URL, dataType : "jsonp", jsonp : "jsoncallback", jsonpCallback : "SMS", cache : true, success : function(service_data) { bi(service_data);

        },
        error : function(msg) {
            alert(JSON.stringify(msg));
        }
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.