相关疑难解决方法(0)

等待来自调用函数的jquery ajax回调

我已经回顾了很多这类问题的答案,现在我对最好的方法感到困惑.考虑到最新的jquery,我想要

  1. 调用ajax函数
  2. 做ajax处理(成功或错误)//工作正常
  3. 成功或错误时将状态返回给调用函数以进行进一步处理

在调用函数(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 jquery callback

18
推荐指数
1
解决办法
6万
查看次数

Extjs,返回Ajax返回值

我在使用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.

有没有办法做出正确的回报回复价值?

谢谢!

ajax extjs

2
推荐指数
1
解决办法
5769
查看次数

javascript函数没有返回正确的值

我有这个检查英国邮政编码的功能.问题是它永远不会返回truefalse- 只是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)

对我而言,它看起来应该总是回归, …

javascript jquery function

1
推荐指数
1
解决办法
460
查看次数

标签 统计

ajax ×2

jquery ×2

callback ×1

extjs ×1

function ×1

javascript ×1