【问题标题】:Ajax call issue in jQueryjQuery中的Ajax调用问题
【发布时间】:2017-10-17 09:25:15
【问题描述】:

我正在使用以下代码从服务器接收一些数据。它总是根据我的请求返回 200 ok 所需的数据。但它不会触发成功或错误事件。如果有人可以帮助我,我将不胜感激。

$('body').on('click','a.btn_details',function(e){
            e.preventDefault();
            var _id = $(this).attr('id');
            var _data = {'action': 'product_details','product_id':_id};
            $.ajax({
                method: 'POST',
                url: '../common/products.php',
                dataType: 'json',
                data: _data,
                succes: function (resp) {
                    alert(resp.name);
                    return false;
                },
                error: function(resp){
                    alert("xd,vj,dfjbj");
                }
            });
            $('#prd_list_cont').hide();
            $('#prd_det_cont').show();
        });

提前致谢,

艾莎·扎法尔

【问题讨论】:

标签: javascript jquery ajax jquery-ui


【解决方案1】:

您的 Ajax 请求中有错误。您需要将 succes 替换为 success

success: function (resp) {
    alert(resp.name);
    return false;
},

祝你好运

【讨论】:

  • 谢谢。有时高效的开发人员会犯拼写错误:D
【解决方案2】:

你能改正它并尝试使用双 s 成功

    $('body').on('click','a.btn_details',function(e){
                e.preventDefault();
                var _id = $(this).attr('id');
                var _data = {'action': 'product_details','product_id':_id};
                $.ajax({
                    method: 'POST',
                    url: '../common/products.php',
                    dataType: 'json',
                    data: _data,
                    success: function (resp) {
                        alert(resp.name);
                        return false;
                    },
                    error: function(resp){
                        alert("xd,vj,dfjbj");
                    }
                });
                $('#prd_list_cont').hide();
                $('#prd_det_cont').show();
            }

);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多