简体   繁体   中英

Ajax call issue in jQuery

I am using the following code to receive some data from server. It always returns 200 ok with required data against my request. But it does not fire success or error event. If anybody can help me in that I'll be grateful to you.

$('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();
        });

Thanks in advance,

Aisha Zafar

You have an error in your Ajax request. You need to replace succes with success :

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

Good luck

Can you correct it and try as success with double 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();
            }

);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM