我在嘗試從 ajax 獲取響應(yīng)時(shí)遇到問題。但是,如果出現(xiàn)問題,它應(yīng)該返回一條錯(cuò)誤消息,如果沒有錯(cuò)誤,它應(yīng)該重定向: - 即使存在錯(cuò)誤,下面的代碼也只是重定向,那么這是使用 post ajax 請(qǐng)求的正確方法嗎?我的代碼如下:$('input[data-post]').click(function(event){ event.preventDefault; var ajaxRequest; var values = $('form').serialize(); var output = $('div.message'); ajaxRequest = $.ajax({ url: $('form').attr('action'), method: "POST", contentType: "text/html; charset=utf-8", dataType: "html", data: values }); ajaxRequest.done(function(){ window.location.href = 'blah blah'; }); ajaxRequest.fail(function(){ // output.html('error'); console.log('error'); }); });
如何返回兩個(gè)ajax響應(yīng)
森欄
2023-11-11 21:18:29