首先,这并不是设置页面的理想方式,但是需要将脚本作为 1 个文件分发.
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.
我在带有 javascript 的其他 xhtml 文档的顶部有一个 php 脚本,并且在某些条件下使用 XHR 将查询字符串发送到页面本身.然后顶部的 php 激活,并将传递的内容存储为会话,然后自行终止(exit()).XHR 是异步的,从不检查它是否返回内容.
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.
但是在 Firefox 3 中,每次发送 XHR 请求时,错误控制台都会抛出错误 no element found
.此外,如果我使用诸如 exit('Done')
之类的出口,Firefox 会抛出 (Done) 的语法错误,就像将其插入可见 DOM 一样.这在 Opera 中似乎不会发生.
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.
是否有更好的方法来存储来自已生成的 xhtml 页面的会话?显然我可以 XHR 到另一个页面,但我更愿意将所有内容都保存在一个脚本中.Firefox 是否将 XHR 对 self 的请求视为对 DOM 的更新?我不知道为什么它会发送此错误.
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.
更新 正如我所说,firefox 仅在发出 XHR 请求时才会显示错误.该页面是有效的 XHTML 并且可以完美运行,除非向页面本身发出 XHR 请求,否则不会出错.
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.
这是一个从对象发出 ajax 请求的 javascript 片段.它创建一个 XHR 对象,没有回调函数,并发布信息.当不引用同一页面时,它可以正常工作.
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); } }, }
php 就是这样做的
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');
}
我也知道我不应该使用innerHTML,但那是另一回事
I'm also aware I shouldn't be using innerHTML but that's another story
错误是这样的
Error: no element found
Source File: http://localhost/ajax.php?1244648094055
Line: 1
请注意,该错误在我使用的 php 页面上引用了一个从未调用过的查询字符串.
Note that the error, while on the php page I'm using, references a query string that is never called.
Firefox 希望得到一些它可以解析为 XML 的东西,并在得到空响应时抛出 XML 解析错误.
Firefox is expecting to get something it can parse as XML back, and throwing an XML parsing error when it gets an empty response.
在 PHP 调用exit()"之前,使用
Before your PHP calls "exit()", use
header('Content-Type: text/plain');
并且 Firefox 不会尝试将响应解析为 XML,并且应该没有错误.
and Firefox will not try to parse the response as XML, and there should be no error.
这篇关于Firefox 错误“未找到元素"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!