//post data
function SubmitForm(method)
{
var login = document.form.login.value;
var password = document.form.password.value;
$.post("../content/backend.php", { login: login,password: password,method: method});
}
我尝试使用上述调用发布数据。在firefox firebug中闪现错误,但没有给我时间评估我唯一可以看到的是jquery的错误指向与下面的代码有关。
// Send the data
try {
xhr.send(s.data);
} catch(e) {
jQuery.handleError(s, xhr, null, e);
}
任何人都知道为什么会这样吗?整个页面发布在下面
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" />
<link href="../pics/homescreen.png" rel="apple-touch-icon" />
<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script src="../javascript/functions.js" type="text/javascript"></script>
<script type="text/javascript" src="../includes/jquery.js"></script>
<script type="text/javascript">
function SubmitForm(method)
{
var login = document.form.login.value;
var password = document.form.password.value;
$.post("../content/backend.php", { login: login,password: password,method: method});
}
</script>
<title>Login</title>
</head>
<body>
<div id="topbar">
<div id="leftnav">
<a href="../index.php"><img alt="home" src="../images/home.png" /></a> </div>
</div>
<div id="title">Login</div>
</div>
<div id="content">
<span class="graytitle">Login</span>
<ul class="pageitem">
<form name="form" method="post" action="#">
<li class="form"><input placeholder="Username" type="text" id="login"/></li>
<li class="form"><input placeholder="Password" type="password" id="password"/></li>
<li class="form"><button onClick="SubmitForm('login')" name="button">Login</button></li>
</ul>
</form>
</div>
<div id="footer"></div>
</body>
</html>
答案 0 :(得分:4)
您的提交函数应返回false以停止事件传播。
function SubmitForm(method)
{
var login = document.form.login.value;
var password = document.form.password.value;
try {
$.post("../content/backend.php", { login: login,password: password,method: method});
} catch(e) {
alert(e);
}
return false
}
停止调用默认的偶数句柄。
还将调用包装在try / catch中以使调试更容易。我们很难调试代码,因为我们没有被调用的脚本。
答案 1 :(得分:0)
而不是
"../content/backend.php"
试试这个
"/yourrootfolder/content/backend.php"