Ajax Success: {return False;}
I want to return false from $.ajax when success is complete: $.ajax({ url: '' + $website_url + 'queries/voorraad_berekenen.php', type: 'post', data: { aantal: $
Solution 1:
From your post I guess that you call a function that contains the $.ajax()
and try to return false
to that function. but you can't do that such way, because AJAX is asynchronous.
It's better to call a function from the ajax success function like following:
$.ajax({
url: '' + $website_url + 'queries/voorraad_berekenen.php',
type: 'post',
data: {
aantal: $(this).parent('form').children('.quantity').val(),
item_number_1: $(this).parent('form').children('.item_number_1').val()
},
success: function(result) {
var returned = true;
if(some_condition_not_satisfied) {
returned = false;
} else {
}
// call a functioncalledFromAjaxSuccess(returned);
}
});
functioncalledFromAjaxSuccess(result) {
if(result) {
alert('TRUE');
} else {
alert('FALSE');
}
}
Solution 2:
Maybe you could try something like this (values 1 and 0 should be changed to the ones that you use):
success: function(result){
if(result === '1'){
// do something
}
elsereturnfalse;
}
Solution 3:
just use asunc false it can work fine i have implemented like that only
just try it
$.ajax({
url: '' + $website_url + 'queries/voorraad_berekenen.php',
type: 'post',
data: {
aantal: $(this).parent('form').children('.quantity').val(),
item_number_1: $(this).parent('form').children('.item_number_1').val()
},
async: false, //=>>>>>>>>>>> here >>>>>>>>>>>
success: function(result) {
returnfalse;
}
});
it is working fine try it once
Solution 4:
<formaction="yourpage"method="post"onsubmit="return matchpass();"><div><label> Name</label><inputtype="text"name="name"id="name"></div><div><label> Email ID</label><inputtype="email"name="email"id="email"></div><div><label> Mobile No</label><inputtype="text"name="mob"maxlength="10"onkeyup="check_if_exists();"autocomplete="off"id="mob"></div><div><buttontype="button" >Send</button></div><spanid="err"></span><div><label> OTP</label><inputtype="password"name="otp"id="otp"maxlength="6"placeholder="****"><spanid="err2"></span></div><div><inputtype="reset"value="Reset"class="reset-btn"><inputtype="submit"name="submit"id="submit"value="Submit" ></div></form><inputtype="hidden"id="otpcheck"/><script>functionmatchpass()
{
$.ajax({
type:"post",
url: "yourpage",
data:{ mobile:mob,otp:otp},
success:function(data)
{
if(data==1)
{
document.getElementById("otpcheck").value=1; //important
}else{
document.getElementById("err2").style.color = "red";
document.getElementById("err2").innerHTML = "invalid OTP Number ";
document.getElementById("otpcheck").value=0; //important
}
}
});
if(document.getElementById("otpcheck").value==0){
returnfalse;
}
}
Solution 5:
I face this problem. then i found the actual solution. use async : false, inside ajax call
functionthisisavailavailusername(uname){
var dataString = 'username='+ uname.value;
var trueorfalse = false;
$.ajax({
type: "post",
url: "/BloodBook/checkavailableusername",
data: dataString,
cache: false,
async : false, //user this then everything oksuccess: function(html){
if(html=="true"){
$('#validusername').html('Available');
trueorfalse = true;
}else{
$('#validusername').html('Not Available');
trueorfalse = false;
}
},
error: function() {
alert("Something Wrong...");
}
});
return trueorfalse;
}
Post a Comment for "Ajax Success: {return False;}"