ajax success false,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: $(this).parent('form').children('.quantity').val(),

item_number_1: $(this).parent('form').children('.item_number_1').val()

},

success: function(result) {

return false;

}

});

This doesn't work. Is there a work around?

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 function

calledFromAjaxSuccess(returned);

}

});

function calledFromAjaxSuccess(result) {

if(result) {

alert('TRUE');

} else {

alert('FALSE');

}

}

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

}

else

return false;

}

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) {

return false;

}

});

it is working fine try it once

Name

Email ID

Mobile No

Send

OTP

function matchpass()

{

$.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){

return false;

}

}

I face this problem. then i found the actual solution. use async : false, inside ajax call

function thisisavailavailusername(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 ok

success: function(html){

if(html=="true"){

$('#validusername').html('Available');

trueorfalse = true;

}else{

$('#validusername').html('Not Available');

trueorfalse = false;

}

},

error: function() {

alert("Something Wrong...");

}

});

return trueorfalse;

}

来源:https://stackoverflow.com/questions/10767128/ajax-success-return-false

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值