silvesterprabu
silvesterprabu

Reputation: 1457

Ajax success function is not working

$.ajax({
    type: 'GET',
    url: 'https://localhost/api/v1/courses?access_token=[MY-ACCESS-TOKEN]',
    cache: false,
    dataType: "jsonp",
    crossDomain: true,
    jsonp: false,
    success: function(data){
        alert("success " + data);
    },
    error: function(error){
        console.log(error)
    }
});

I am trying to access this API. I am able to see a response in Firebug but it is not firing the success function of $.ajax. How can I solve this one?

Upvotes: 0

Views: 5239

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074266

You're setting the option jsonp: false. The jsonp option tells jQuery what name to give the JSONP callback function. So you're telling jQuery to use "false" as the callback function name. Fortunately, jQuery doesn't actually use that name (I just tried it — if it did, the JSONP coming back would fail), but putting that option there effectively turns off the dataType: "jsonp" you specified earlier, making jQuery try an actual ajax (non-JSONP) request, which fails.

Remove the jsonp option entirely to let jQuery do a JSONP request and to allow it to control the callback name.

Upvotes: 4

Related Questions