Bug Tracker

Ticket #13388 (closed bug: fixed)

Opened 18 months ago

Last modified 12 months ago

Ajax request not returning responseXML

Reported by: Nao Owned by: jaubourg
Priority: high Milestone: 1.10
Component: ajax Version: 1.9.1
Keywords: Cc:
Blocking: Blocked by:

Description

Hello.

Yesterday I found a bug in jQuery's behavior when doing a synchronous request to my server. (Yes, I know it's bad, but this is the only sync request in my entire, very large codebase, and can hardly be rewritten without adding too much unnecessary code, so I'd rather keep it this way.)

Whether you send a dataType (to xml) or not, it doesn't matter, having it set on auto or xml is the same. My server sends a proper string containing well-formed XML, and it is seen as text by jQuery, i.e. it returns a responseText but not responseXML object.

This bug can be reproduced in both jQuery 2.0 and jQuery 1.9.1, but not in jQuery 1.9.0.

I fixed it on my side by returning a text string without any tags (which had the added benefit of not wasting bandwidth and making my code shorter :)), but I'd rather not have this bug stay in the codebase, too afraid many sites will break and not understand why.

So I traced through the code, and I think the culprit is at line 8560 in jquery-git.js, or rather the missing lines of code that were in lines 8514 and 8516-8520 in jquery-1.9.0.js, which reference a bug fix for this unrelated report:

http://bugs.jquery.com/ticket/4958

The report above was reopened last year, but I don't know why the fix was removed.

Here's an old jsfiddle snippet I found that reproduces this. Select jQuery 1.9.0, it works. Select jQuery (Edge) (i.e. 1.9.1pre) or jQuery 2.0.0b1, it doesn't work (responseXML is undefined).

 http://jsfiddle.net/kxQLg/6/

Hopefully this is enough information to help you guys fix this without too much hassle.

Change History

comment:1 Changed 18 months ago by jaubourg

  • Status changed from new to assigned
  • Component changed from unfiled to ajax
  • Priority changed from undecided to high
  • Version changed from git to 1.9.1
  • Milestone changed from None to 1.9.2
  • Owner set to jaubourg

Confirmed, the xml is parsed and accessible in the success handler though, so no need to move to text data. The following works:

success: function( xml ) {
    alert(xml.getElementsByTagName("test")[0].childNodes[0].nodeValue);
}
Last edited 18 months ago by jaubourg (previous) (diff)

comment:2 Changed 18 months ago by Nao

Yup, as I said, it's a synchronous JAX bug only, not an AJAX bug :) Switching to asynchronous mode is the 'easy' fix, but it's not a permanent solution if you wish for jQuery to remain compatible with most existing scripts.

(It was already hard enough for me to figure out I had to update my .attr('checked') and similar to .prop(), as the 1.9 upgrade grade doesn't clearly state that it's become mandatory in this version, just like it was in v1.6.0...)

comment:3 follow-up: ↓ 4 Changed 18 months ago by anonymous

Please, we need responseXML back.

comment:4 in reply to: ↑ 3 Changed 18 months ago by dmethvin

Use an older version then. We'll get a fix in the next release. We're not doing a new release immediately for one bug. Stop posting these messages everywhere.

comment:5 Changed 18 months ago by anonymous

If you guys don't delete people's comments, then I will stop.

comment:6 Changed 18 months ago by dmethvin

Stop anonymously harrassing people who are trying to help you be a better developer. If you have something to say, say it under your name.

comment:7 follow-up: ↓ 8 Changed 18 months ago by Sam

I understand it's not wise to do a new release for the ajax bug ;) ... but in the mean time(so we can carry on testing / debugging our apps ready for the fix) - could someone provide a clearer work around than switch to async - because that makes no difference as far as I can tell.

comment:8 in reply to: ↑ 7 Changed 18 months ago by jaubourg

Replying to Sam:

I understand it's not wise to do a new release for the ajax bug ;) ... but in the mean time(so we can carry on testing / debugging our apps ready for the fix) - could someone provide a clearer work around than switch to async - because that makes no difference as far as I can tell.

There is one in the first comment.

comment:9 Changed 18 months ago by anonymous

Thanks for your time jaubourg. I did read that. Over and over. It just didn't go in. After many hours the penny has dropped. Yes, available in success handler but not useful in dataFilter. I think it's because I'm not very clever. Either that or I'm sitting too close to the screen... come to think of it, my dose does feel a little shorter! I'm going with muppet. Any advances on muppet? Sorry. Thank you. Gone.

comment:10 Changed 18 months ago by Nao

Or just retrieve responseText and parse that. If you can change the output format from the server, even easier to deal with. :)

comment:11 Changed 18 months ago by jaubourg

#13414 is a duplicate of this ticket.

comment:12 Changed 18 months ago by Ivan Petrov

dmethvin, when you introduce a bug like that which will definitely break many applications, you should provide an immediate fix and build. You guys should pay more attention on QA before releasing new versions. You should also remember how big is your community and how many apps you will break with such bugs.

comment:13 Changed 18 months ago by dmethvin

@Ivan, this bug was just introduced on Monday of this week. If it affects your code, just stay with the previous 1.9.0 until 1.9.2 is released.

comment:14 Changed 18 months ago by rahul

Hi, my jquery version shows is 1.6.4 and i used success:function(myData){/*rest of code*/} server response is well formed xml as i checked in firebug. data type in ajax call is set as "xml" and is a get operation. the myData.responseXML is coming as undefined, i tried async:false and async:true but no effect. when i changed the success:function'''(myData,stat,xmlData){...} it works fine.

comment:15 Changed 17 months ago by jaubourg

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixes #11151, #13388. Minor refactor of response conversion and when/where responseXXX fields are set on the jqXHR. Close gh-1164. Changeset: 69b3d5ce0f081d3f113b2917495f35df160f8522

comment:16 Changed 17 months ago by jaubourg

Fixes #11151, #13388. Minor refactor of response conversion and when/where responseXXX fields are set on the jqXHR. Close gh-1164.

(Cherry-picked from 69b3d5ce0f081d3f113b2917495f35df160f8522)

Changeset: eebc77849cebd9a69025996939f930cbf9b1bae1

comment:17 Changed 14 months ago by anonymous

I see that the 1.10 beta 1 is out. Will 1.10 include this fix? I have not seen a 1.9.2 beta.

comment:18 Changed 14 months ago by dmethvin

  • Milestone changed from 1.9.2 to 1.10

comment:19 Changed 12 months ago by cphill02@…

Since this is still not fixed in jquery-1.10.1... is there some workaround everyone is using?

comment:20 Changed 12 months ago by dmethvin

Seems like "this" is fixed, see the fiddle reported above with 1.x selected.

 http://jsfiddle.net/kxQLg/107/

Note: See TracTickets for help on using tickets.