简体   繁体   English

这段代码有什么问题?

[英]what is wrong with this code?

I have created a jquery click event to delete something from the xml file.The code is as follows:我创建了一个jquery点击事件,从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);
            }
        }); 
    }
});

But the thing is, its not working with google chrome, but working correctly with mozilla firefox.但问题是,它不能与 google chrome 一起使用,但可以与 mozilla firefox 一起正常工作。 Any ideas as to why this is happening??关于为什么会发生这种情况的任何想法? Is it because of cache!?是因为缓存吗!?

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.我会检查 JSON 你回来看看它是否返回你期望给定 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.此外,您应该检查 Javascript 错误。 jQuery's AJAX API does very strict validation on JSON strings when the dataType is set to JSON. jQuery 的 AJAX API 对 JSON 字符串进行非常严格的验证,当 dataType 设置为 Z0ECD11C1D7A28D740188A23D 时It can be rather unforgiving.这可能是相当无情的。

I have had issues getting data back from a JSON object using jQuery in Chrome in the past.过去,我在 Chrome 中使用 jQuery 从 JSON object 获取数据时遇到问题。 My solution was to make sure that the JSON that is being parsed is strictly formed.我的解决方案是确保正在解析的 JSON 是严格形成的。 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.这是在我正在开发的应用程序中工作的 JSON object 的示例。

{ "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". { "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"] } } } “56,1922532075705.-69.2615720447455”] } } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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