我在下面的代码中遗漏了什么?我有点不知所措。
$("a[id^='submitspam']").click(function () {
var thisForm = $(this).attr('id');
var com_id = $(this).attr('id').substring(11);
var thisFormFull = '#' + thisForm;
$.ajax({
type: "POST",
url: "/songs/spam.php",
data: "command=mark_spam&cid=" + com_id,
complete: function(data){
messageList = 'contentspam-' + com_id;
$('span#' + messageList).html(data.responseText);
$(thisFormFull).hide();
$('span#' + messageList).fadeIn();
}
});
return false;
});
答案 0 :(得分:2)
适合我。我使用您的代码创建了jsfiddle,然后单击IE 8中的链接会生成一个请求。我使用Fiddler来检查HTTP请求:
POST /songs/spam.php HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: en-US,en;q=0.7,es;q=0.3
Referer: http://fiddle.jshell.net/josh3736/Ghy5C/show/
Accept: */*
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; .NET CLR 1.1.4322; .NET4.0C; InfoPath.3)
Host: fiddle.jshell.net
Content-Length: 23
Connection: Keep-Alive
Pragma: no-cache
command=mark_spam&cid=1
即使AJAX请求404s(jsfiddle的服务器上没有spam.php),链接也会在请求完成后隐藏。顺便说一下,你应该使你的回调函数成为success
回调而不是complete
回调,这样你的UI就不会报告操作成功,而实际上是有错误。