Ren*_*ann 5 javascript ajax jquery
我想false从完成$.ajax时返回success:
$.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;
}
});
Run Code Online (Sandbox Code Playgroud)
这不起作用.有工作吗?
the*_*dox 12
从你的帖子我想你调用一个函数包含$.ajax()并尝试return false该函数.但你不能这样做,因为AJAX是异步的.
最好从ajax成功函数调用一个函数,如下所示:
$.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');
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27121 次 |
| 最近记录: |