天道不一定酬所有勤
但是,天道只酬勤
Hollis出品的全套Java面试宝典不来了解一下吗?

Uncaught TypeError: Cannot call method 'toLowerCase' of undefined

Hollis出品的全套Java面试宝典不来了解一下吗?

出错代码:

 $.ajax({
                 type: "GET",
                 url: 'firstRequest.json?id=' + $(this).val(),
                 async: false,
                 dataType: "json",
                 success: function(data){
                    if(data.deleteable == "true"){
                        $.ajax({
                             type: "GET",
                             url: 'secondRequest.json?id=' + $(this).val(),
                             async: false,
                             dataType: "json",
                             success: function(data){
                                if(data.result=="success"){
                                    alert("删除成功");
                                    reloadPage();
                                }else{
                                    alert("删除失败");
                                }
                             },
                             error: function(XMLHttpRequest, textStatus, errorThrown) {
                                alert("请求失败!");
                             }
                        });
                    }else{
                        alert("无法删除!!!");
                        return false;
                    }
                 },
                 error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("请求失败!");
                 }
            });

修改之后代码

 var clicked = this;
 $.ajax({
                 type: "GET",
                 url: 'firstRequest.json?id=' + $(clicked).val(),
                 async: false,
                 dataType: "json",
                 success: function(data){
                    if(data.deleteable == "true"){
                        $.ajax({
                             type: "GET",
                             url: 'secondRequest.json?id=' + $(clicked).val(),
                             async: false,
                             dataType: "json",
                             success: function(data){
                                if(data.result=="success"){
                                    alert("删除成功");
                                    reloadPage();
                                }else{
                                    alert("删除失败");
                                }
                             },
                             error: function(XMLHttpRequest, textStatus, errorThrown) {
                                alert("请求失败!");
                             }
                        });
                    }else{
                        alert("无法删除!!!");
                        return false;
                    }
                 },
                 error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("请求失败!");
                 }
            });
赞(0)
如未加特殊说明,此网站文章均为原创,转载必须注明出处。HollisChuang's Blog » Uncaught TypeError: Cannot call method 'toLowerCase' of undefined
Hollis出品的全套Java面试宝典不来了解一下吗?

评论 抢沙发

HollisChuang's Blog

联系我关于我