我使用jQuery 1.7.2版本,我提交使用Ajax這樣的。點擊不是Ajax請求後,工作
$("input#addPostSubmit").click(function(){
$.ajax({
//this is the php file that processes the data and send mail
url: BASE_URL+"post/ajaxcreate",
//POST method is used
type: "POST",
//pass the data
data: $("#addImage").serialize(),
//Do not cache the page
cache: false,
//success
success: function (html) {
var obj = jQuery.parseJSON(html);
if(obj.Status == 'Success'){
$("#error").removeClass('hide');
$("#error").addClass('success');
$("#error").html(obj.Message);
$.fn.colorbox.resize();
setTimeout(function(){$.fn.colorbox.close()},5000);
window.parent.location.reload();
}
if(obj.Status == 'Fail'){
$('.add_post_submit').html('<input type="button" id="addPostSubmit" value="Create" />');
$("input#addPostSubmit").removeAttr('disabled');
$("#error").removeClass('hide');
$("#error").addClass('error');
error = obj.Message.split(';');
html = '<ul>';
for(a=0;a<error.length;a++){
html += '<li>'+error[a]+'</li>';
}
html += '</ul>';
$("#error").html(html);
$('html').css({overflow: 'hidden'});
$.fn.colorbox.resize();
}
}
});
});
我的存在,例如空不允許在表單域之一,當服務器驗證窗體和返回錯誤我顯示它時,當我再次點擊按鈕,它不工作...
它工作正常,但問題是當Ajax請求完成,服務器返回 任何形式的錯誤,然後提交按鈕沒有工作請幫助我,我卡住了....
郵政**'ERROR MESSAGE' **,你從服務器得到 – thecodeparadox
可能是你應該使用'返回false;'的'click'函數中的第一行,這樣的默認操作被取消出。 – SexyBeast
給一個jsfiddle – Aravind