我已经回顾了很多这类问题的答案,现在我对最好的方法感到困惑.考虑到最新的jquery,我想要
在调用函数(doAjax)中,如何等待回调然后完成成功或错误的处理(在这种情况下,它成功清除表单,出错时保持原样)
感谢任何建议,
艺术 [编辑] 你们发现有一个错字,打电话应该是doAnAjax不做阿贾克斯
$(function () {
doAnAjax(Url, data, function (myRtn) {
if (myRtn == "success") {
resetForm($('#myForm'));
resetForm($('form[name=addChlGrp]'));
} else {
$('.rtnMsg').html("Opps! Ajax Error");
}
});
});
function doAnAjax(newUrl, data) {
$.ajax({
url: newUrl,
async: true,
dataType: 'html',
beforeSend: function () {
$('.rtnMsg').html("<img src=_cssStyleImg_-A-loading.gif>");
},
type: "GET",
data: data,
cache: false,
success: function (data, textStatus, xhr) {
$('.rtnMsg').html(data);
myRtnA = "Success"
return myRtnA;
},
error: function (xhr, textStatus, errorThrown) {
$('.rtnMsg').html("opps: " + textStatus …Run Code Online (Sandbox Code Playgroud) 我在使用Ajax时遇到问题.
function GetGrantAmazonItemCnt(){
var cnt;
Ext.Ajax.request({
url : '',
params : {},
success :function(response){
cnt = response.responseText;
}
});
return cnt;
}
Run Code Online (Sandbox Code Playgroud)
问题是,在获得ajax响应之前,它返回cnt.所以它总是返回NULL.
有没有办法做出正确的回报回复价值?
谢谢!
我有这个检查英国邮政编码的功能.问题是它永远不会返回true或false- 只是undefined.
function PostcodeAnywhere_Interactive_FindByPostcode_v1_00(Key, Postcode, UserName) {
var retval;
$.getJSON("https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/FindByPostcode/v1.00/json3.ws?",
{
Key: Key,
Postcode: Postcode,
UserName: UserName
},
function (response) {
// Test for an error
if (response.Items.length == 1 && typeof(response.Items[0].Error) != "undefined") {
// Show the error message
retval = false;
} else {
// Check if there were any items found
if (response.Items.length == 0){
retval = false;
} else {
retval = true;
}
}
});
return retval;
}
Run Code Online (Sandbox Code Playgroud)
对我而言,它看起来应该总是回归, …