错误线是这样的:
contxt.replaceWith(safe_copy[id]).prepend("<span class='error'>"+jsonObj.data+"</span>");
虽然该replaceWith
语句工作得很好,但数据没有得到“ prepended
”。
更完整的代码:
contxt = $(this).parents('div[style^="display"]');
id = $(this).attr('id');
$.ajax({
url: "/submit/myposts",
type: "POST",
data: "action=edit&post="+$(this).attr('id').match(/[0-9]+/)[0]+"&data="+encodeURIComponent(text),
success: function(data){
loading.remove();
jsonObj = $.parseJSON(data);
if(jsonObj.code == "0")
block.html(jsonObj.data);
else
contxt.replaceWith(safe_copy[id]).prepend("<span class='error'>"+jsonObj.data+"</span>");
},
error: function(){
loading.remove();
contxt.replaceWith(safe_copy[id]).prepend("<span class='error'>An error occurred. Please try again.</span>");
}
});