This is the code I have. I want to prevent the form from submitting if the message i receive from the php side is 0 (an error occured). If the message received is 1 I want to submit the form.
$(document).ready(function(){
$('#form').submit(function(e){
register();
});
});
function register(){
$.ajax({
type:"POST",
url:"submit.php",
data: $('#form').serialize(),
dataType: "json",
success: function(msg){
if(parseInt(msg)==1){
window.location=msg;
}
else if(parseInt(msg)==0){
$('#error_out').html(msg);
}
}
});
}
This is the code I have. I want to prevent the form from submitting if the message i receive from the php side is 0 (an error occured). If the message received is 1 I want to submit the form.
$(document).ready(function(){
$('#form').submit(function(e){
register();
});
});
function register(){
$.ajax({
type:"POST",
url:"submit.php",
data: $('#form').serialize(),
dataType: "json",
success: function(msg){
if(parseInt(msg)==1){
window.location=msg;
}
else if(parseInt(msg)==0){
$('#error_out').html(msg);
}
}
});
}
Share
asked Jul 11, 2011 at 18:05
user461316user461316
9133 gold badges12 silver badges31 bronze badges
4 Answers
Reset to default 5after register();
include return false;
$('#form').submit(function(e){
e.preventDefault();
//do whatever you want
});
As I understand ,Try use this:
after register();
include return false;
if it doesn't work then rename register();
to register(e);
and then include e.preventDefault(); e.stopPropagation();
hope it works.