这段代码有什么问题?
我创建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的罪魁祸首可能就在这里。我会检查您返回的 JSON,看看它是否返回给定 ID 所期望的结果。
另外,您应该检查 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.
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.
过去,我在 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"]
}
}
}