$.ajaxエラーコールバック関数で提供されるxhr.ResponseTextを使用します。例を次に示します。
ノート!xhr.response textは、エラーページを表すすべての醜いhtml文字列を返します。より具体的にしたい場合は、別のオプションがあります。
サーバー側のアプリでは、tryとcatch句を使用します。エラーを見つけたら、それをテキストとしてresponse.writeに送信し、response.end();を使用します。これは最善の方法ではありませんが、機能します。
もう1つのオプションは、jsonを使用して、キャッチされたエラーメッセージとresponse.writeを構造化することです。これにより、XHRオブジェクトは構造化されたoopの方法で情報を保持します。
$.ajax({
type: "POST",
url: "/Administration/Create",
data: {
EntityParentID: data.rslt.parent.attr("id"),
EntityName: data.rslt.name
},
success: function (response)
{
var node = data.rslt.obj;
node.attr("id", response.EntityID);
},
error: function (xhr, ajaxOptions, thrownError)
{
alert("Error Occured During Creation of Entity.");
alert(xhr.responseText); //This will alert an ugly html string...
$.jstree.rollback(data.rlbk);
},
dataType: "json"
});