|
From: Tom Cole on 16 Apr 2008 15:30 I have a rather complicated business application that uses Ajax. Part of this form requires uploading documents, which I cannot do using Ajax, so I post the form to an IFrame. This part works just fine. The problem I have is that my server process returns some content to the IFrame to complete form processing and to report any errors that might have occured. Here's an example of what may be written back: <html> <head> <script type="text/javascript"> function completed() { window.parent.reportsCompleted(); } </script> <body onload="completed();"> <error>The document type .doc is not supported.</error> </body> </html> Now this does properly call the reportsCompleted method of the parent frame. The problem I am having is reading the contents of any <error> tags if they exist: function reportsCompleted() { var frame = frames['upload_frame']; if (frame.document.getElementsByTagName("error").length > 0) { // there were errors... var message = "The following error(s) occured:"; for (var i = 0; i < frame.document.getElementsByTagName("error").length; i++) { message += "\n" + frame.document.getElementsByTagName("error")[i].nodeValue(); } alert(message); } } The problem is that I never get the contents of the error tags displayed. I only see an alert window that says "The following error(s) occured:". What am I doing wrong?
From: RoLo on 17 Apr 2008 00:23 On Apr 16, 3:30 pm, Tom Cole <tco...(a)gmail.com> wrote: > I have a rather complicated business application that uses Ajax. Part > of this form requires uploading documents, which I cannot do using > Ajax, so I post the form to an IFrame. This part works just fine. > > The problem I have is that my server process returns some content to > the IFrame to complete form processing and to report any errors that > might have occured. Here's an example of what may be written back: > > <html> > <head> > <script type="text/javascript"> > function completed() { > window.parent.reportsCompleted();} > > </script> > <body onload="completed();"> > <error>The document type .doc is not supported.</error> > </body> > </html> > > Now this does properly call the reportsCompleted method of the parent > frame. The problem I am having is reading the contents of any <error> > tags if they exist: > > function reportsCompleted() { > var frame = frames['upload_frame']; > if (frame.document.getElementsByTagName("error").length > 0) { // > there were errors... > var message = "The following error(s) occured:"; > for (var i = 0; i < > frame.document.getElementsByTagName("error").length; i++) { > message += "\n" + > frame.document.getElementsByTagName("error")[i].nodeValue(); > } > alert(message); > } > > } > > The problem is that I never get the contents of the error tags > displayed. I only see an alert window that says "The following > error(s) occured:". > > What am I doing wrong? why not use .innerHTML instead of your non existent .nodeValue()? http://developer.mozilla.org/en/docs/DOM:element.nodeValue
From: Thomas 'PointedEars' Lahn on 17 Apr 2008 01:39 Tom Cole wrote: > [...] > The problem I have is that my server process returns some content to > the IFrame to complete form processing and to report any errors that > might have occured. Here's an example of what may be written back: > > <html> > <head> > <script type="text/javascript"> > function completed() { > window.parent.reportsCompleted(); > } > </script> > <body onload="completed();"> > <error>The document type .doc is not supported.</error> > </body> > </html> > > [...] The problem I am having is reading the contents of any <error> > tags if they exist: > > function reportsCompleted() { > var frame = frames['upload_frame']; > if (frame.document.getElementsByTagName("error").length > 0) { // > there were errors... Use instead: if (frame) { // add feature test here var c = frame.document.getElementsByTagName("error"); var len = c.length; if (len > 0) { > var message = "The following error(s) occured:"; > for (var i = 0; i < > .length; i++) { var message = []; for (var i = 0; i < len; i++) { > message += "\n" + > frame.document.getElementsByTagName("error")[i].nodeValue(); message.push(c[i].nodeValue; > } > alert(message); } window.alert(message.join("\n")); > } > } } > The problem is that I never get the contents of the error tags > displayed. I only see an alert window that says "The following > error(s) occured:". > > What am I doing wrong? Using non-HTML elements in a supposed-to-be HTML document, and calling a property although it is not a method. http://jibbering.com/faq/#FAQ4_43 http://validator.w3.org/ PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
From: gunnrosebutpeace on 17 Apr 2008 03:20 the <error> is not standard HTML elements then different browsers have diffent behavior on unknow tag for IE, you should define a namespace for custom elements (xmlns:my="http://xxxx....", then use my:error, then use document.getELementsByTagName("error")) for Firefox, you need not to define namespace, but you have to write document.getElementsByTagName("my:error"); It'd better to use standard HTML element (p, span) and innerHTML. On Apr 17, 2:30 am, Tom Cole <tco...(a)gmail.com> wrote: > I have a rather complicated business application that uses Ajax. Part > of this form requires uploading documents, which I cannot do using > Ajax, so I post the form to an IFrame. This part works just fine. > > The problem I have is that my server process returns some content to > the IFrame to complete form processing and to report any errors that > might have occured. Here's an example of what may be written back: > > <html> > <head> > <script type="text/javascript"> > function completed() { > window.parent.reportsCompleted();} > > </script> > <body onload="completed();"> > <error>The document type .doc is not supported.</error> > </body> > </html> > > Now this does properly call the reportsCompleted method of the parent > frame. The problem I am having is reading the contents of any <error> > tags if they exist: > > function reportsCompleted() { > var frame = frames['upload_frame']; > if (frame.document.getElementsByTagName("error").length > 0) { // > there were errors... > var message = "The following error(s) occured:"; > for (var i = 0; i < > frame.document.getElementsByTagName("error").length; i++) { > message += "\n" + > frame.document.getElementsByTagName("error")[i].nodeValue(); > } > alert(message); > } > > } > > The problem is that I never get the contents of the error tags > displayed. I only see an alert window that says "The following > error(s) occured:". > > What am I doing wrong?
From: Henry on 17 Apr 2008 06:09 On Apr 17, 8:20 am, gunnrosebutpeace wrote: > the <error> is not standard HTML elements then different > browsers have diffent behavior on unknow tag > > for IE, you should define a namespace for custom elements > (xmlns:my="http://xxxx....", then use my:error, then use > document.getELementsByTagName("error")) > for Firefox, you need not to define namespace, but you have > to write document.getElementsByTagName("my:error"); > It'd better to use standard HTML element (p, span) and > innerHTML. Because different browsers have (and should be expected to have) different behaviour when they encounter an unrecognised element in an HTML document the specifics of the behaviour of just two of those browsers is of very little use or relevance. Because the response that includes the message is being generated it would be possible to generate it in any form, and the simplest form would be to take the character sequence that would otherwise appear in the "error" element and appropriately escape it for inclusion in a javascript string literal context and insert it as a string literal argument to the - reportsCompleted - function call:- // with double quotes and line terminators in the string (at minimum) // replaces with their equivalent escape sequences. window.parent.reportsCompleted( "The document type .doc is not supported" ); (with either no argument or an empty string as an argument in the event that there was no error to report.) Or assign it to a local variable (perhaps called 'error' for example, but preferably something longer and less likely to coincide with a pre- existing window property):- // with double quotes and line terminators in the string (at minimum) // replaces with their equivalent escape sequences. var error = "The document type .doc is not supported." - and have the reportsCompleted - function access it as:- frames['upload_frame'].error And in the (apparently likely( event that it is anticipated that there be more than one error to report the string literals of the errors could instead appear in an array literal.
|
Next
|
Last
Pages: 1 2 3 Prev: A javascript based browser home page app Next: What is a findName reference? |