Firefox错误“找不到元素” [英] Firefox error 'no element found'

查看:179
本文介绍了Firefox错误“找不到元素”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这不是设置页面的理想方式,但是需要将脚本分配为1个文件。



我有一个PHP脚本在JavaScript的另一个xhtml文档的顶部,并在某些情况下使用XHR发送一个查询字符串到页面本身。然后在顶部的php激活,并将通过的内容存储为一个会话,然后杀死自己(exit())。 XHR是异步的,并且从不检查它是否返回内容。

然而,在Firefox 3中,错误控制台会抛出错误找不到元素每当XHR请求被发送时,另外,如果我使用 exit('Done')之类的出口,Firefox会抛出(Done)的语法错误,就好像将其插入到可见的DOM中一样。这似乎并没有发生在Opera中。



有没有更好的方法来存储从一个已经生成的xhtml页面的会话?显然,我可以将XHR转到另一个页面,但是我宁愿将它全部保留在一个脚本中。 Firefox是否将XHR请求视为DOM的更新?我不知道为什么发送这个错误。




更新正如我所说的,firefox只会在发出XHR请求时抛出错误。该页面是有效的XHTML和完美的工作,没有错误,除非XHR请求是对页面本身。



我想知道为什么发送错误是因为它真的没有返回任何东西。



这是一个从一个对象发出ajax请求的javascript代码片段。
它创建一个没有回调函数的XHR对象,并发布信息。它没有引用同一页面时正常工作。

  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); }},}

和php一样



($ _ 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('完成');
}

我也知道我不应该使用innerHTML,但这是另一个故事






错误是这个

 错误:找不到元素
源文件:http://localhost/ajax.php?1244648094055
行:1

请注意,在我使用的php页面上,错误引用了一个永远不会被调用的查询字符串。



解析方案

在PHP调用exit()之前,使用

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

和Firefox不会尝试将响应解析为XML,并且应该没有错误。 p>

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.

解决方案

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.

这篇关于Firefox错误“找不到元素”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆