Side navigation
#12707 closed bug (notabug)
Opened October 11, 2012 05:22PM UTC
Closed October 11, 2012 06:08PM UTC
Last modified October 11, 2012 06:20PM UTC
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: |
Description
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"; $.ajax({ 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); } });
Attachments (0)
Change History (4)
Changed October 11, 2012 05:33PM UTC by comment:1
owner: | → kelvinator |
---|---|
status: | new → pending |
Changed October 11, 2012 05:48PM UTC by comment:2
status: | pending → new |
---|
Replying to [comment:1 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?
Changed October 11, 2012 06:08PM UTC by comment:3
resolution: | → notabug |
---|---|
status: | new → closed |
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.
Changed October 11, 2012 06:20PM UTC by comment:4
Thanks for your time and the clarification.
Why *wouldn't* it cause an error? Function names can't have dots in them.