15

Here is my ajax call.

 $.ajax({
    type: "GET",
    url: "http://example.com/v1/search?keyword=r",
    dataType: "jsonp",
    crossDomain: true,
    success: function (responseString) {
        alert(responseString);
    },
    error: function (xhr, errorType, exception) {
        var errorMessage = exception || xhr.statusText;
        alert(errorMessage);
    }
});

Response from my example url

    {
    "response": [{
        "attributes": {
            "type": "enge",
            "url": "/services/data/v24.0/sobjects/Challenge__c/a0GZ0000005Vvh4MAC"
        },
        "name": "Really",
        "end_date": "2013-02-07T15:26:00.000+0000",
        "total": 350.0,
        "registered_members": 0.0,
        "id": "30",
        "type": "Design",
        "id": "a0GZ0000005Vvh4MAC",
        "start_date": "2012-11-19T16:52:00.000+0000",
        "description": "This is my really cool challenge",
        "remaining_days": 28.0,
        "categories__r": [{
            "attributes": {
                "type": "Category__c",
                "url": "/services/data/Category__c/a08Z0000000RNI2IAO"
            },
            "id": "0RNI2IAO",
            "display_name": "Andy"
        }, {
            "attributes": {
                "type": "Category__c",
                "url": "/services/Category__c/a08Z0000000RNI3IAO"
            },
            "id": "a0O",
            "display_name": "ADR"
        }]
    }

    }],
    "count": 1
}

i'm trying to make an cross domain call and getting error

jQuery180014405992737595236_1357861668479 was not called

Update

Well i tried to use dataType:"json" but at that point getting error

No Transport
iJade
  • 23,144
  • 56
  • 154
  • 243

4 Answers4

10

That suggests either a network error or an end point that doesn't return a JSONP response.

(I'm guessing the DNS lookup failure I get when testing it is because that isn't your real URL (please use example.com for example URLs, that is what it is there for) if not, then that is your problem).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    It's the endpoint not serving correct jsonp, if it was a network error he would get the according error code instead. – Christoph Jan 10 '13 at 10:25
  • 1
    @jade — That's a JSON response, not a JSONP response. You need to wrap it with a function call to the function specified in the callback argument (and use an application/javascript content type instead of application/json) – Quentin Jan 10 '13 at 10:26
  • the main point is in fact the server must answer jQuery180014405992737595236_1357861668479({"theJson":"value}) your answer is rude – Damien MIRAS Sep 14 '15 at 18:17
5

It's an incorrect JSONP Response. The server needs to process the callback=nameOfCallbackFunction argument of the GET Request and serve it as a function wrapper.

The proper response then should look like this:

nameOfCallbackFunction({"yourjson": "here"});
Christoph
  • 50,121
  • 21
  • 99
  • 128
  • so u mean that's not a jsonp response but json response.I tried with json dataType but getting No Transport error.I have updated question – iJade Jan 10 '13 at 10:31
  • @jade Is this a crossdomain call (Pointing to a different location than where your page comes from)? If yes, you can only use JSONP or use [CORS](http://enable-cors.org/) to prevent [SOP](http://de.wikipedia.org/wiki/Same-Origin-Policy) errors. – Christoph Jan 10 '13 at 10:38
  • well actually i dont know if its cross domain.I got an error while not using cross domain "No Transport", so just googled and some suggested using cross domain would resolve the issue – iJade Jan 10 '13 at 10:39
  • ok i just used $.support.cors = true; before ajax call but its giving error Access Denied – iJade Jan 10 '13 at 10:43
  • Well, "No Transport" or "Access Denied" sound like a typical violation of SOP. Are you testing from your local machine (localhost) and/or using Internet Explorer? You need to either use CORS or JSONP, no other option for you. – Christoph Jan 10 '13 at 10:45
  • well i'm testing from localhost using an html page, it not hosted – iJade Jan 10 '13 at 10:46
  • You cannot make crossdomain calls with localhost unless using a development with experimental flags. – Christoph Jan 10 '13 at 10:47
2

I know this is an old thread but have struggled to get a cross domain ajax example working. I read much about using dataType: jsonp and support.cors = true but got a 200 - success but a parseerror.

I then read in this thread about using one or the other. I then changed the dataType: to json and left the support.cors = true and it worked. Finally . . .

This may help someone else who encounters the same issue.

0

The reason why you have the error JQueryXXXX is because there is an error in the url you are calling, you need to introduce "?callback=?", so looks like:

"http://example.com/v1/search?callback=?keyword=r"

Also If you call a .php remember:

header('Content-Type: application/json; charset=utf8');