4
我有以下代碼通過ajax將我的表單數據發佈到upload.php。在php文件中,服務器檢查上傳的文件大小/格式等。如何告訴ajax這是否失敗並停止顯示成功消息?向ajax報告錯誤
$.ajax({
type: 'POST',
url: 'upload.php',
data: dataString,
success: function() {
$('#getintouch .alert-error').slideUp();
$('#getintouch .alert-success').slideDown();
$('#submit').data('loading-text', 'Sent');
$('#submit').button('loading');
}
});
我想補充:在的情況下, 5xx HTTP代碼,你應該使用「錯誤」AJAX回調:http://api.jquery.com/Ajax_Events/ –
我用方法2但成功事件是stil儘管將響應代碼設置爲500並將腳本設置爲die(),但仍然會被觸發。 – JazzyP
啊哈! http_response_code需要php 5.4,我正在使用5.3。我使用下面的代碼來代替header(':',true,500); – JazzyP