Friday, May 6, 2011

Jquery post problem

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

Im trying to post data using the above call. In firefox firebug flashes up an error but dose not give me time to evaluate the only thing I can see is an error point to jquery which relates to the following code.

// Send the data
 try {
  xhr.send(s.data);
 } catch(e) {
  jQuery.handleError(s, xhr, null, e);
 }

Any one know why this is happening? Entire page posted below

<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>
From stackoverflow
  • Your submit function should return false to stop event propagation.

    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
    }
    

    To stop the default even handler from being called.

    Also wrap the call inside a try/catch to make debugging easier. It's hard for us to debug the code since we don't have the called script.

0 comments:

Post a Comment