这段代码有什么问题?

发布于 2024-11-04 18:19:41 字数 1395 浏览 0 评论 0原文

我创建了一个 jquery click 事件来从 xml 文件中删除某些内容。代码如下:

$(".delete_engine").bind("click",function(){
    var del = $(this);
    var id = del.attr("id");
    var c = confirm("You sure want to delete this?");

    if(c)
    {
        /* $(this).next('.pclass').remove();
        $(this).prev('.rurl').remove();
        $(this).remove();*/
        $.ajax({
            type: "POST",
            url: "http://localhost:8080/cPEP_UI/Engine_engine_delete",
            data: "eid="+id,
            dataType: "json",
            success: function(data) {
                $('#light').html("<img src='loading.gif' alt='loading gif'/>");
                $('#light').css("display","block");
                $('#fade').css("display","block");
                if(data.update == "success"){
                    del.parent().next().remove();
                    del.parent().remove();
                    $('#light').html(data.message+" "+data.update);
                }
            },
            error:function(xhr,err){
                //alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
                alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
                $('.error').html("responseText: "+xhr.responseText);
            }
        }); 
    }
});

但问题是,它不能与 google chrome 一起使用,但可以与 mozilla firefox 一起正常工作。关于为什么会发生这种情况有什么想法吗?是因为缓存的原因吗!?

I have created a jquery click event to delete something from the xml file.The code is as follows:

$(".delete_engine").bind("click",function(){
    var del = $(this);
    var id = del.attr("id");
    var c = confirm("You sure want to delete this?");

    if(c)
    {
        /* $(this).next('.pclass').remove();
        $(this).prev('.rurl').remove();
        $(this).remove();*/
        $.ajax({
            type: "POST",
            url: "http://localhost:8080/cPEP_UI/Engine_engine_delete",
            data: "eid="+id,
            dataType: "json",
            success: function(data) {
                $('#light').html("<img src='loading.gif' alt='loading gif'/>");
                $('#light').css("display","block");
                $('#fade').css("display","block");
                if(data.update == "success"){
                    del.parent().next().remove();
                    del.parent().remove();
                    $('#light').html(data.message+" "+data.update);
                }
            },
            error:function(xhr,err){
                //alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
                alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
                $('.error').html("responseText: "+xhr.responseText);
            }
        }); 
    }
});

But the thing is, its not working with google chrome, but working correctly with mozilla firefox. Any ideas as to why this is happening?! Is it because of cache!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我只土不豪 2024-11-11 18:19:41

你的罪魁祸首可能就在这里。我会检查您返回的 JSON,看看它是否返回给定 ID 所期望的结果。

if(data.update == "success"){
    del.parent().next().remove();
    del.parent().remove();
    $('#light').html(data.message+" "+data.update);
}

另外,您应该检查 Javascript 错误。当 dataType 设置为 JSON 时,jQuery 的 AJAX API 对 JSON 字符串进行非常严格的验证。这可能相当无情。

Your culprit is probably here. I would check the JSON that you're getting back to see if it's returning the results you're expecting for a given ID.

if(data.update == "success"){
    del.parent().next().remove();
    del.parent().remove();
    $('#light').html(data.message+" "+data.update);
}

Also, you should check for Javascript errors. jQuery's AJAX API does very strict validation on JSON strings when the dataType is set to JSON. It can be rather unforgiving.

一片旧的回忆 2024-11-11 18:19:41

过去,我在 Chrome 中使用 jQuery 从 JSON 对象获取数据时遇到了问题。我的解决方案是确保正在解析的 JSON 格式严格。特别是,请确保所有键和值都用双引号引起来。

下面是一个在我正在开发的应用程序中运行的 JSON 对象的示例。

{“db”:{“计数”:“4”,
“记录”:{
“124”:[“124”,“cooldood137”,“43.1922532075705,-76.2615720447455”],
“345”:[“345”,“jillchill9”,“45.1922532075705,-78.2615720447455”],
“987”:[“987”,“bobdabanka”,“43.4922532075705,-76.1615720447455”],
“654”:[“654”,“foobarlounge”,“46.1922532075705,-79.2615720447455”],
"674" : ["674", "ohai!lolcat", "56.1922532075705,-69.2615720447455"]
}
}
}

I have had issues getting data back from a JSON object using jQuery in Chrome in the past. My solution was to make sure that the JSON that is being parsed is strictly formed. In particular, make sure that all keys and values are wrapped in double quotes.

Here is an example of a JSON object that worked in an app I am working on.

{ "db" : { "count" : "4",
"records" : {
"124" : ["124", "cooldood137", "43.1922532075705,-76.2615720447455"],
"345" : ["345", "jillchill9", "45.1922532075705,-78.2615720447455"],
"987" : ["987", "bobdabanka", "43.4922532075705,-76.1615720447455"],
"654" : ["654", "foobarlounge", "46.1922532075705,-79.2615720447455"],
"674" : ["674", "ohai!lolcat", "56.1922532075705,-69.2615720447455"]
}
}
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文