Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox error 'no element found'

Tags:

First off, this isn't exactly the ideal way of setting up a page, however there's a need to distribute a script as 1 file.

I have a php script at the top of an otherwise xhtml document with javascript, and under certain conditions use XHR to send a query string to the page itself. The php at the top then activates, and stores the passed content as a session, and then kills itself (exit()). The XHR is async and is never checked to see if it returns content.

However in Firefox 3, the error console throws an error no element found every time the XHR request gets sent. Also, if I use an exit such as exit('Done'), Firefox throws a syntax error of (Done) as if it inserts it into the visible DOM. This doesn't seem to happen in Opera.

Is there a better way to store a session from an already generated xhtml page? Obviously I could XHR to another page, but I would prefer to keep it all on one script. Does Firefox treat XHR requests to self as updates to the DOM? I don't know why it's sending this error.


Update As I said, firefox only thows the error when the XHR request is made. The page is valid XHTML and works perfectly, without error unless the XHR request is made to the page itself.

I was wondering why it was sending the error because it really doesn't return anything.

Here's a javascript snippet that makes a ajax request from an object. It creates a XHR object, without a callback function, and posts the information. It works properly when not referencing the same page.

 var saveState = { saveContent: function(updateActiveMenu) {
    var sendState = new ajaxObject(gV.url);
    if (!updateActiveMenu) {
        var storageContainer = document.getElementById("StorageContainer").innerHTML;
        var menu = document.getElementById("Nav").innerHTML;
        sendState.update("Containerstring="+urlencode(storageContainer)+"&Nav="+urlencode(menu)+"&Active="+gV.activeMenuItem, 'POST', true);    } }, }

And the php does this

if (isset($_REQUEST['Containerstring']) && isset($_REQUEST['Nav']) && isset($_REQUEST['Active'])) {
  $_SESSION['Containerarray'] = (saveContainer(regulateEscapes(urldecode($_REQUEST['Containerstring']))));
  $_SESSION['Navarray'] = (saveNav(regulateEscapes(urldecode($_REQUEST['Nav']))));
  $_SESSION['Active'] = $_REQUEST['Active'];
  exit('Done'); 
}

I'm also aware I shouldn't be using innerHTML but that's another story


The error is this

Error: no element found
Source File: http://localhost/ajax.php?1244648094055 
Line: 1

Note that the error, while on the php page I'm using, references a query string that is never called.

like image 394
Ian Elliott Avatar asked Jun 10 '09 14:06

Ian Elliott


People also ask

What is XML parsing error?

XML Parser ErrorWhen trying to open an XML document, a parser-error may occur. If the parser encounters an error, it may load an XML document containing the error description. The code example below tries to load an XML document that is not well-formed. You can read more about well-formed XML in XML Syntax.

What is Firefox startup cache?

The Firefox cache temporarily stores images, scripts, and other parts of websites you visit in order to speed up your browsing experience.


1 Answers

Firefox is expecting to get something it can parse as XML back, and throwing an XML parsing error when it gets an empty response.

Before your PHP calls "exit()", use

header('Content-Type: text/plain');

and Firefox will not try to parse the response as XML, and there should be no error.

like image 177
NickFitz Avatar answered Sep 30 '22 07:09

NickFitz