我正在使用jquery調用一個ASP MVC控制器。其中返回一個局部視圖。即一堆的HTML試圖解析xhr.responseText
在出現錯誤的情況下,我想爲用戶填充一些信息,但ASP MVC發送完整頁面,因此我需要從中取出文本。
我已經試過:
$('#edit').ajaxError(function (e, xhr, settings, exception) {
var item = xhr.responseText.text();
var response = item.match(/.*<body.*>(.*)<\/body>.*/);
if (!response) {
$(this).html('Error: ' + xhr.status + ' Message:' + xhr.statusText);
}
else {
$(this).html(response);
};
});
,但我得到遺漏的類型錯誤:[其次xhr.responseText內容]有沒有一種方法文本
如果我叫賽直接的responseText我得到空結果是。
我猜我有一些根本性的誤解怎麼回事,這樣如果有人能幫助...
這幫助我得到了博德內容,其中xhr.responseText返回了一個完整的頁面HTML。 –