Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12707 closed bug (notabug)

function with dot in jsonpcallback triggers the error handler

Reported by: kelvinator Owned by: kelvinator
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


When the callback function is inside an object/function (function name with a dot), the ajax jsonp call will trigger the error handler to execute even the call succeeds (status=200).

 var testing1 = function (data) {
        alert("Call testing1 success!");

    var testObj = {
        testing2 : function(data) {
            alert("Call testing2 success!");

    var aUrl = "http://useYourOwnUrl";
        url: aUrl,
        dataType: "jsonp",
        type : "GET",
        crossDomain : "true",
        jsonp : "callback",
        jsonpCallback: "testObj.testing2",
        error : function(jqXHR, textStatus, errorThrown){
            alert("Got an error...jqXHR=" + jqXHR.status + ", textStatus =" + textStatus + ", errorThrown=" + errorThrown);

Change History (4)

comment:1 Changed 10 years ago by dmethvin

Owner: set to kelvinator
Status: newpending

Why *wouldn't* it cause an error? Function names can't have dots in them.

comment:2 in reply to:  1 Changed 10 years ago by kelvinator

Status: pendingnew

Replying to dmethvin:

Why *wouldn't* it cause an error? Function names can't have dots in them.

There are two scenario here. The first one is: How come the callback function is called as well? If it is an error, the error condition should be triggered but not the callback. Both the callback and error condition are triggered.

Another is: the function is inside of the object, should it be considered as the function as well?

comment:3 Changed 10 years ago by dmethvin

Resolution: notabug
Status: newclosed

Using the API incorrectly has undefined behavior. The ajax response didn't have an error, the code that called the API had an error.

The docs say jsonpCallback should be a string that is the "callback function name". Although "testObj.testing2" is a string, it is not a function name.

jQuery neither eval()s the jsonpCallback string nor parses it as JavaScript. If it did, it would have to divine the scope of testObj (global scope, local scope, closure?) at some point during program execution (the time of the $.ajax call, the time of the completed ajax request, or immediately before the callback invocation?) to call the function (with this as window, or as a method with this as testObj?)

jsonpCallback is a string representing the callback function name.

comment:4 in reply to:  3 Changed 10 years ago by kelvinator

Thanks for your time and the clarification.

Note: See TracTickets for help on using tickets.