[Proto-Scripty] Re: Prototype XML bug???
Hi again, I should have said that the symptom you report in your original post is crazy weird. If it's really happening, it (also) looks like a browser bug. I assume it only happens in one browser. But I wouldn't have thought it was Prototype. In this code: // this will fail!!! $('ajStatus').value = transport.responseXML.getElementsByTagName('status') [0].firstChild.nodeValue; ...you're not actually using Prototype for anything other than the `$ ('ajStatus')` part (which I'm guessing isn't what's failing), the rest is pure DOM and JavaScript. Do you have somewhere you can host a live, working (but minimalist) example of this problem? It'd be interesting to take a look at. FWIW -- and good luck, -- T.J. On Sep 13, 3:39 pm, "T.J. Crowder" wrote: > Hi, > > > Inside an onSuccess: if you attempt to reference an non-existant xml element > > using getlelementsbytagname() it throws a catch and prototype takes it upon > > itself to return from the onSuccess instead of returning an "undefined" to > > the calling routine. > > Exceptions in Ajax callbacks are routed to the onException > handler:http://api.prototypejs.org/ajax/ajax/request/ > > > By exiting out of the onSuccess function it A) > > prevents the remainder of the code from being executed; > > Right. This isn't a Prototype thing, trying to dereference something > that isn't pointing at anything causes an exception, and exceptions do > that. :-) You can use a try/catch block in your code to handle the > exception gracefully (or test what you're dereferencing first and only > dereference it if it's pointing to something). > > > B) can leave the > > browser in an unstable state; > > In what way? If that really happens, it's a browser bug and should be > reported to the browser provider. *Nothing* you do in JavaScript > should be able to make a browser unstable. > -- > T.J. Crowder > Independent Software Consultant > mail: tj / crowder software / com > web: www / crowder software / com > > On Sep 13, 2:55 pm, Phil Petree wrote: > > > > > The problem with prototype is: > > > Inside an onSuccess: if you attempt to reference an non-existant xml element > > using getlelementsbytagname() it throws a catch and prototype takes it upon > > itself to return from the onSuccess instead of returning an "undefined" to > > the calling routine. By exiting out of the onSuccess function it A) > > prevents the remainder of the code from being executed; B) can leave the > > browser in an unstable state; C) makes it nearly impossible to debug. > > > On Sat, Sep 11, 2010 at 9:16 PM, Gregory Nicholas > > > wrote: > > > i have always struggles getting xml in javascript to work consistently > > > across browsers. i usually have stuck to traversing a little more > > > manually than using the getelementsbytagname method: > > > > > > > update > > > > > > > > > > > > > > > > > > > var fields = e.responseXML.documentElement.childNodes; > > > var method = fields[0].firstChild.nodeValue; > > > var result = fields[1].firstChild.nodeValue; > > > var status = result.childNodes[0].firstChild.nodeValue; > > > var message = result.childNodes[1].firstChild.nodeValue; > > > > // or a for loop: > > > for (var i = 0, total = fields.length; i < total; i++) { > > > var field = fields[i]; > > > if (field.nodeName == 'result') { > > > var fieldNodes = field.childNodes; > > > var status = fieldNodes[0].firstChild.nodeValue; > > > var message = fieldNodes[1].firstChild.nodeValue; > > > } > > > } > > > > On Sep 8, 6:25 am, Phil Petree wrote: > > > > Essentially, you have to reference the XML data in node order, if you > > > > try > > > to > > > > reference the first node AFTER you have referenced all the other nodes, > > > the > > > > first node gets returned as empty. > > > > > Take an XML data set defined as: > > > > > > > > OK > > > > 22 > > > > bart > > > > 09/01/2010 > > > > . > > > > . > > > > . > > > > > > > > > == THIS WORKS ON THE FIRST DATA NODE > > > > // Now, in the javascript on the form do this (and this works fine): > > > > $('ajStatus').value = > > > > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu > > > e; > > > > > $('ajRecord').value = > > > > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu > > > e; > > > > > $('ajUserid').value = > > > > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu > > > e; > > > > > $('ajDate').value = > > > > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > > > > == THIS FAILS ON THE FIRST DATA NODE > > > > // Turn it around and do this (and the last value will NEVER get set): > > > > $('ajRecord').value = > > > > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu > > > e; > > > > > $('ajUserid').value = > > > > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu > > > e; > > > > > $('ajDate').value = >
[Proto-Scripty] Re: Prototype XML bug???
Hi, > Inside an onSuccess: if you attempt to reference an non-existant xml element > using getlelementsbytagname() it throws a catch and prototype takes it upon > itself to return from the onSuccess instead of returning an "undefined" to > the calling routine. Exceptions in Ajax callbacks are routed to the onException handler: http://api.prototypejs.org/ajax/ajax/request/ > By exiting out of the onSuccess function it A) > prevents the remainder of the code from being executed; Right. This isn't a Prototype thing, trying to dereference something that isn't pointing at anything causes an exception, and exceptions do that. :-) You can use a try/catch block in your code to handle the exception gracefully (or test what you're dereferencing first and only dereference it if it's pointing to something). > B) can leave the > browser in an unstable state; In what way? If that really happens, it's a browser bug and should be reported to the browser provider. *Nothing* you do in JavaScript should be able to make a browser unstable. -- T.J. Crowder Independent Software Consultant mail: tj / crowder software / com web: www / crowder software / com On Sep 13, 2:55 pm, Phil Petree wrote: > The problem with prototype is: > > Inside an onSuccess: if you attempt to reference an non-existant xml element > using getlelementsbytagname() it throws a catch and prototype takes it upon > itself to return from the onSuccess instead of returning an "undefined" to > the calling routine. By exiting out of the onSuccess function it A) > prevents the remainder of the code from being executed; B) can leave the > browser in an unstable state; C) makes it nearly impossible to debug. > > On Sat, Sep 11, 2010 at 9:16 PM, Gregory Nicholas > > > > wrote: > > i have always struggles getting xml in javascript to work consistently > > across browsers. i usually have stuck to traversing a little more > > manually than using the getelementsbytagname method: > > > > > update > > > > > > > > > > > > > var fields = e.responseXML.documentElement.childNodes; > > var method = fields[0].firstChild.nodeValue; > > var result = fields[1].firstChild.nodeValue; > > var status = result.childNodes[0].firstChild.nodeValue; > > var message = result.childNodes[1].firstChild.nodeValue; > > > // or a for loop: > > for (var i = 0, total = fields.length; i < total; i++) { > > var field = fields[i]; > > if (field.nodeName == 'result') { > > var fieldNodes = field.childNodes; > > var status = fieldNodes[0].firstChild.nodeValue; > > var message = fieldNodes[1].firstChild.nodeValue; > > } > > } > > > On Sep 8, 6:25 am, Phil Petree wrote: > > > Essentially, you have to reference the XML data in node order, if you try > > to > > > reference the first node AFTER you have referenced all the other nodes, > > the > > > first node gets returned as empty. > > > > Take an XML data set defined as: > > > > > > OK > > > 22 > > > bart > > > 09/01/2010 > > > . > > > . > > > . > > > > > > > == THIS WORKS ON THE FIRST DATA NODE > > > // Now, in the javascript on the form do this (and this works fine): > > > $('ajStatus').value = > > > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu > > e; > > > > $('ajRecord').value = > > > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu > > e; > > > > $('ajUserid').value = > > > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu > > e; > > > > $('ajDate').value = > > > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > > > == THIS FAILS ON THE FIRST DATA NODE > > > // Turn it around and do this (and the last value will NEVER get set): > > > $('ajRecord').value = > > > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu > > e; > > > > $('ajUserid').value = > > > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu > > e; > > > > $('ajDate').value = > > > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > > > // this will fail!!! > > > $('ajStatus').value = > > > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu > > e; > > > -- > > You received this message because you are subscribed to the Google Groups > > "Prototype & script.aculo.us" group. > > To post to this group, send email to > > prototype-scriptacul...@googlegroups.com. > > To unsubscribe from this group, send email to > > prototype-scriptaculous+unsubscr...@googlegroups.com > s%2bunsubscr...@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubsc
Re: [Proto-Scripty] Re: Prototype XML bug???
The problem with prototype is: Inside an onSuccess: if you attempt to reference an non-existant xml element using getlelementsbytagname() it throws a catch and prototype takes it upon itself to return from the onSuccess instead of returning an "undefined" to the calling routine. By exiting out of the onSuccess function it A) prevents the remainder of the code from being executed; B) can leave the browser in an unstable state; C) makes it nearly impossible to debug. On Sat, Sep 11, 2010 at 9:16 PM, Gregory Nicholas wrote: > i have always struggles getting xml in javascript to work consistently > across browsers. i usually have stuck to traversing a little more > manually than using the getelementsbytagname method: > > > update > > > > > > > var fields = e.responseXML.documentElement.childNodes; > var method = fields[0].firstChild.nodeValue; > var result = fields[1].firstChild.nodeValue; > var status = result.childNodes[0].firstChild.nodeValue; > var message = result.childNodes[1].firstChild.nodeValue; > > // or a for loop: > for (var i = 0, total = fields.length; i < total; i++) { > var field = fields[i]; > if (field.nodeName == 'result') { >var fieldNodes = field.childNodes; >var status = fieldNodes[0].firstChild.nodeValue; >var message = fieldNodes[1].firstChild.nodeValue; > } > } > > > > > On Sep 8, 6:25 am, Phil Petree wrote: > > Essentially, you have to reference the XML data in node order, if you try > to > > reference the first node AFTER you have referenced all the other nodes, > the > > first node gets returned as empty. > > > > Take an XML data set defined as: > > > > OK > > 22 > > bart > > 09/01/2010 > > . > > . > > . > > > > > > == THIS WORKS ON THE FIRST DATA NODE > > // Now, in the javascript on the form do this (and this works fine): > > $('ajStatus').value = > > > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu > e; > > > > $('ajRecord').value = > > > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu > e; > > > > $('ajUserid').value = > > > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu > e; > > > > $('ajDate').value = > > > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > > > == THIS FAILS ON THE FIRST DATA NODE > > // Turn it around and do this (and the last value will NEVER get set): > > $('ajRecord').value = > > > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu > e; > > > > $('ajUserid').value = > > > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu > e; > > > > $('ajDate').value = > > > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > > > // this will fail!!! > > $('ajStatus').value = > > > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu > e; > > -- > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > To post to this group, send email to > prototype-scriptacul...@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Prototype XML bug???
i have always struggles getting xml in javascript to work consistently across browsers. i usually have stuck to traversing a little more manually than using the getelementsbytagname method: update var fields = e.responseXML.documentElement.childNodes; var method = fields[0].firstChild.nodeValue; var result = fields[1].firstChild.nodeValue; var status = result.childNodes[0].firstChild.nodeValue; var message = result.childNodes[1].firstChild.nodeValue; // or a for loop: for (var i = 0, total = fields.length; i < total; i++) { var field = fields[i]; if (field.nodeName == 'result') { var fieldNodes = field.childNodes; var status = fieldNodes[0].firstChild.nodeValue; var message = fieldNodes[1].firstChild.nodeValue; } } On Sep 8, 6:25 am, Phil Petree wrote: > Essentially, you have to reference the XML data in node order, if you try to > reference the first node AFTER you have referenced all the other nodes, the > first node gets returned as empty. > > Take an XML data set defined as: > > OK > 22 > bart > 09/01/2010 > . > . > . > > > == THIS WORKS ON THE FIRST DATA NODE > // Now, in the javascript on the form do this (and this works fine): > $('ajStatus').value = > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu e; > > $('ajRecord').value = > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu e; > > $('ajUserid').value = > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu e; > > $('ajDate').value = > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > == THIS FAILS ON THE FIRST DATA NODE > // Turn it around and do this (and the last value will NEVER get set): > $('ajRecord').value = > transport.responseXML.getElementsByTagName('record')[0].firstChild.nodeValu e; > > $('ajUserid').value = > transport.responseXML.getElementsByTagName('userid')[0].firstChild.nodeValu e; > > $('ajDate').value = > transport.responseXML.getElementsByTagName('date')[0].firstChild.nodeValue; > > // this will fail!!! > $('ajStatus').value = > transport.responseXML.getElementsByTagName('status')[0].firstChild.nodeValu e; -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.