2

Ajax呼び出しを行っていますが、サーバーからエラーが発生します。

問題は、以下のメッセージが表示されることです。

HTTP Status 756 - Error while processing the request.

--------------------------------------------------------------------------------

type Status report

message Error while processing the request.

description Cannot find message associated with key http.756

そして、上記のすべてのテキストではなく、完全なエラーレポートからエラーメッセージのみを取得したいと思います。どうやってやるの?

しかし、実際の応答は

<html><head><title>Apache Tomcat/5.0.28 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 756 - Error while processing the request.</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Error while processing the request.</u></p><p><b>description</b> <u>Cannot find message associam<D‡üñÔE(1@@ähttp.756</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.0.28</h3></body></html>​

エラーメッセージを取得したい場所から。

4

3 に答える 3

2

responseHTMLを取り戻すと、次のようにメッセージを取得できます...

var div = document.createElement("div");

div.innerHTML = response;

var errorMsg = [].filter.call(div.getElementsByTagName("b"), function(b) {
    return b.textContent == "message";
})[0].nextElementSibling.textContent || "Unknown error";

jsFiddle


それが単なるテキストだったら...

-これにより、最初の行の後にテキストが抽出されます。一致するものが見つからない場合は、「不明なエラー」が返されます。

var errorMsg = (response.split("\n")[0].match(/^HTTP Status \d+ - (.+)$/) 
                || [])[1]
                || "Unknown error";

jsFiddle

代わりに、以下の行と一致させたい場合message

var errorMsg = (response.match(/^message (.+)$/m) || [])[1] || "Unknown error";

jsFiddle

于 2012-07-20T06:06:29.980 に答える
1

この作業例を確認してください: 正規表現

(?<=-\s).*

また

(?<=[0-9]\s-\s).*

これにより、正確なメッセージが取得されます。Error while processing the request.

編集

含まれている場合HTML、これは機能します:更新された正規表現

(?<=<h1>).*(?=</h1>)
于 2012-07-20T06:19:34.597 に答える
0

私は次のJavaScriptコードで答えを得ました。

var res = "Error Message : '";

var bonly = data.responseText.match(/<h1>(.*?)<\/h1>/);
if (bonly && (bonly.length > 1)) {
    res += bonly[1];
}
res += "'. Error Code : ";
res += data.status;
return res;
于 2012-07-20T07:30:53.107 に答える