JSONP $.ajax fails if type is passed #884

Closed
arthurgouveia opened this Issue Dec 19, 2013 · 5 comments

3 participants

@arthurgouveia

Hello.

I was using jQuery 2.0 for a mobile app, wrapped by PhoneGap and I had a JSONP call to an API which was working, but then when I switched to zepto.js, my requests were not sending any data anymore.

Turns out that I previously had a standard JSON call and had a type: 'post' set on the parameters of my ajax call. Once switched to JSONP, jQuery ignored this type and was making a GET request, as expected for a JSONP. Zepto still makes the GET request but sends no data. I'm wondering if that shouldn't be ignored in case a dataType: 'jsonp' was set and therefore avoid this data not being sent.

Can be reproduced here (create a requestbin for yourself if you don't want to see other people's):

Zepto: http://codepen.io/anon/pen/ljfhA
jQuery: http://codepen.io/anon/pen/cnvzh

@mislav
Collaborator

type: POST and dataType: jsonp don't mix, as they're mutually exclusive and don't make any sense. Why are you using Ajax that way?

I'm reluctant to call this a Zepto bug, even if it doesn't match jQuery's behavior, because it's in the area of unsupported combination of options and therefore the outcome will be unpredictable.

@arthurgouveia

I was making JSON calls before, when still in development, so there was no need for JSONP, and it was a POST. I'm not using Ajax this way :)

I understand POST and JSONP don't mix. I'm just saying that ATM, jQuery 'knows' that because you're making a JSONP, it should ignore whatever type you pass. Zepto also 'knows' that and makes a GET, but sends no data in the request.

I found this because I forgot to update my code when switching from an Ajax POST, JSON to a Ajax JSONP.
Was a mistake, and I thought it might help to report.

@mislav
Collaborator

We definitely thank you for reporting. I understand how you might have came across this bug. However, as I said, I'm reluctant to fix this since it would mean we support this style of using Ajax, which we definitely don't.

Would you be terribly disappointed if we didn't fix it? Do you think other people might stumble on the same problem as well?

@arthurgouveia

I believe that mistakes couldn't definitely happen, but then again, not having fallbacks for developers' mistakes will force then to pay more attention to the changes done, which was my case. Since jQuery 2.0 was doing so, thought Zepto might want to do the same in this situation.

No problem if you feel that it's all good. It's all good for me as well.

Feel free to close the issue and thanks for the comprehension.

@paranoidjk

I came across this problem too.
I understand that it's a wrong way to use jsonp whit POST,but I still hope that zepto can behavior just like jquery, which auto change POST to GET when datatype is jsonp.

Can this PR acceptable ? maybe a console error to warning the developer.

@mislav mislav closed this in 1fc2868 Jul 12, 2016
@mislav mislav removed the Discuss label Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment