gpt4 book ai didi

jquery远程验证

转载 作者:行者123 更新时间:2023-12-01 07:35:35 24 4
gpt4 key购买 nike

我的表单中有 3 个远程验证,其中 3 个在 Firefox 控制台中没有错误。第三个在 IE 中无法正常工作。IE 给我错误“对象不支持此属性”

这在 IE check.php 中给出了错误:

< ?php

$sql="select * from people where email = '".$email."'";
$row=mysql_query($sql,$db_connection);
if (!$row)
{
die('Error: ' . mysql_error());
}

if (mysql_num_rows($row) > 0)
{
$output = false;
}
else
{
$output = true;
}
echo json_encode($output);

?>

这是相应的jquery:

email: {// compound rule
required: true,
email: true ,
remote: "check.php"
},

任何想法为什么它在 IE 中抛出对象错误。注意 Firefox 错误控制台不显示任何错误!谢谢

最佳答案

我们必须查看页面才能确定,但​​ IE 出现“对象不支持此属性或方法”错误的常见原因是页面上有一个元素,其 nameid 属性包含与隐式全局变量相同的名称。

IE6-7 有一个不幸的非标准行为,即将命名/IDd 元素的引用复制到窗口对象的属性中:

<div id="foo">bar</div>

alert(window.foo); // the div node

这意味着它们与变量共享一个命名空间:

<div id="foo">bar</div>

var foo= 3;
alert(window.foo); // now 3

但是,在另一个不幸的非标准行为中,如果你不告诉它你想要一个变量,IE 就会感到困惑。它尝试将任何新值分配给元素节点本身,这将失败:

<div id="foo">bar</div>

foo= 3; // implicit global variable in other browsers. Error in IE

当您忘记 var 并在函数中意外创建全局变量时,也会发生这种情况:

function bof() {
foo= 3; // Error in IE
}

因此,您需要仔细检查脚本来查找已分配的变量,而无需记住为它们包含 var 语句。这不仅仅是一个好的实践(并且是 future ECMA262-5 的“严格模式”JS 所要求的) — 它可以防止 IE 变得愚蠢并破坏你的页面。

顺便说一句:

$sql="select * from people where email = '".$email."'";

是一个危险的SQL注入(inject)安全漏洞。构建 SQL 查询时,您必须对要插入字符串文字的任何文本使用 mysql_real_escape_string()

关于jquery远程验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2226003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com