Ok So I have a basic login page with a form:
<form name="register" class="form-horizontal" id="signup" onsubmit="return validateForm(this);" action="check.php">
<div class="control-group input-append">
<label for="text" class="control-label">Name</label>
<div class="controls">
<input id="name" name="name" type="name" placeholder="Enter your name"/>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="passwd" class="control-label">Password</label>
<div class="controls">
<input id="pass" name="pass" type="pass" placeholder="Enter your password"/>
</div>
</div>
<br>
<div class="control-group">
<div class="controls">
<div class="left1">
<input type="submit" name="submit" class="btn btn-success"/>
</div>
</div>
</div>
<br>
</form>
On clicking submit I need to post the name and password to check.php. I do not want the browser to refresh the page to check.php.
It should get the resulting JSON array, parse it and based on that redirect if the login is successful.
Right now i can either post or get but not both. And I don't want the browser to refresh the page to check.php.
UPDATE:
I'm still not getting this to work. Have a look please.
<form class="form-horizontal" id="login-form">
<div class="control-group input-append">
<label for="text" class="control-label">Email</label>
<div class="controls">
<input name="email" id="email" type="email" value="" placeholder="Enter your email"/>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="passwd" class="control-label">Password</label>
<div class="controls">
<input name="passwd" id="passwd" type="password" value="" placeholder="Enter your password"/>
</div>
</div>
<br>
<div class="control-group">
<div class="controls">
<div class="left1">
<input type="button" id="login" value="Login" class="btn btn-success"/>
</div>
</div>
</div>
<br>
</form>
</div>
</div>
</body>
<script>
$('#login').click(function(){
$.ajax({
url:"login.php",
type:'POST',
data: $("#login-form").serialize()
}).done(function(data){
alert(JSON.stringify(data));
});
}
});
</script>