我正在使用$ .post jQuery函数。成功部分没问题,但错误部分从动作网址接收一些我不知道它到底是什么以及如何用jQuery解析它的代码。
动作网址是“wp-comments-post.php”(WordPress评论发布)。
让我说我试图用这些功能解析它但没有成功: jQuery.parseJSON() - jQuery.parseHTML()
这是我通过console.log(错误)获得的代码:
({
readyState: 4,
getResponseHeader: (function (e) {
var t;
if (2 === x) {
if (!c) {
c = {};
while (t = Tn.exec(a)) c[t[1].toLowerCase()] = t[2]
}
t = c[e.toLowerCase()]
}
return null == t ? null : t
}),
getAllResponseHeaders: (function () {
return 2 === x ? a : null
}),
setRequestHeader: (function (e, t) {
var n = e.toLowerCase();
return x || (e = v[n] = v[n] || e, y[e] = t), this
}),
overrideMimeType: (function (e) {
return x || (p.mimeType = e), this
}),
statusCode: (function (e) {
var t;
if (e) if (2 > x) for (t in e) m[t] = [m[t], e[t]];
else N.always(e[N.status]);
return this
}),
abort: (function (e) {
var t = e || T;
return l && l.abort(t), k(0, t), this
}),
state: (function () {
return n
}),
always: (function () {
return i.done(arguments).fail(arguments), this
}),
then: (function () {
var e = arguments;
return b.Deferred(function (n) {
b.each(t, function (t, o) {
var a = o[0],
s = b.isFunction(e[t]) && e[t];
i[o[1]](function () {
var e = s && s.apply(this, arguments);
e && b.isFunction(e.promise) ? e.promise().done(n.resolve).fail(n.reject).progress(n.notify) : n[a + "With"]
(this === r ? n.promise() : this, s ? [e] : arguments)
})
}), e = null
}).promise()
}),
promise: (function (e) {
return null != e ? b.extend(e, r) : r
}),
pipe: (function () {
var e = arguments;
return b.Deferred(function (n) {
b.each(t, function (t, o) {
var a = o[0],
s = b.isFunction(e[t]) && e[t];
i[o[1]](function () {
var e = s && s.apply(this, arguments);
e && b.isFunction(e.promise) ? e.promise().done(n.resolve).fail(n.reject).progress(n.notify) : n[a + "With"]
(this === r ? n.promise() : this, s ? [e] : arguments)
})
}), e = null
}).promise()
}),
done: (function () {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function (t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})
(arguments), n ? o = u.length : r && (s = t, c(r))
}
return this
}),
fail: (function () {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function (t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})
(arguments), n ? o = u.length : r && (s = t, c(r))
}
return this
}),
progress: (function () {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function (t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})
(arguments), n ? o = u.length : r && (s = t, c(r))
}
return this
}),
complete: (function () {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function (t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})
(arguments), n ? o = u.length : r && (s = t, c(r))
}
return this
}),
success: (function () {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function (t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})
(arguments), n ? o = u.length : r && (s = t, c(r))
}
return this
}),
error: (function () {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function (t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})(arguments),
n ? o = u.length : r && (s = t, c(r))
}
return this
}),
responseText: "<!DOCTYPE html>\n<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such
that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhii
jjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqp
rqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovp
pqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9
j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono
\n-->\n<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"rtl\" lang=\"fa-IR\">\n<head>\n\t<meta http-equiv=\"Content
-Type\" content=\"text/html; charset=utf-8\" />\n\t<title>\u0648\u0631\u062F\u067E\u0631\u0633 › \u062E\u0637\
u0627</title>\n\t<style type=\"text/css\">\n\t\thtml {\n\t\t\tbackground: #f9f9f9;\n\t\t}\n\t\tbody {\n\t\t\tbackgrou
nd: #fff;\n\t\t\tcolor: #333;\n\t\t\tfont-family: sans-serif;\n\t\t\tmargin: 2em auto;\n\t\t\tpadding: 1em 2em;\n\t\t
\t-webkit-border-radius: 3px;\n\t\t\tborder-radius: 3px;\n\t\t\tborder: 1px solid #dfdfdf;\n\t\t\tmax-width: 700px;\n
\t\t}\n\t\th1 {\n\t\t\tborder-bottom: 1px solid #dadada;\n\t\t\tclear: both;\n\t\t\tcolor: #666;\n\t\t\tfont: 24px Ge
orgia, \"Times New Roman\", Times, serif;\n\t\t\tmargin: 30px 0 0 0;\n\t\t\tpadding: 0;\n\t\t\tpadding-bottom: 7px;\n
\t\t}\n\t\t#error-page {\n\t\t\tmargin-top: 50px;\n\t\t}\n\t\t#error-page p {\n\t\t\tfont-size: 14px;\n\t\t\tline-hei
ght: 1.5;\n\t\t\tmargin: 25px 0 20px;\n\t\t}\n\t\t#error-page code {\n\t\t\tfont-family: Consolas, Monaco, monospace;
\n\t\t}\n\t\tul li {\n\t\t\tmargin-bottom: 10px;\n\t\t\tfont-size: 14px ;\n\t\t}\n\t\ta {\n\t\t\tcolor: #21759B;\n\t\
t\ttext-decoration: none;\n\t\t}\n\t\ta:hover {\n\t\t\tcolor: #D54E21;\n\t\t}\n\t\t.button {\n\t\t\tdisplay: inline-b
lock;\n\t\t\ttext-decoration: none;\n\t\t\tfont-size: 14px;\n\t\t\tline-height: 23px;\n\t\t\theight: 24px;\n\t\t\tmar
gin: 0;\n\t\t\tpadding: 0 10px 1px;\n\t\t\tcursor: pointer;\n\t\t\tborder-width: 1px;\n\t\t\tborder-style: solid;\n\t
\t\t-webkit-border-radius: 3px;\n\t\t\tborder-radius: 3px;\n\t\t\twhite-space: nowrap;\n\t\t\t-webkit-box-sizing: bor
der-box;\n\t\t\t-moz-box-sizing: border-box;\n\t\t\tbox-sizing: border-box;\n\t\t\tbackground: #f3f3f3;\n\
t\t\tbackground-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4));\n\t\t\tbackground
-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4);\n\t\t\tbackground-image: -moz-linear-gradient(top, #fefefe
, #f4f4f4);\n\t\t\tbackground-image: -o-linear-gradient(top, #fefefe, #f4f4f4);\n\t\t\tbackground-image: linea
r-gradient(to bottom, #fefefe, #f4f4f4);\n\t\t\tborder-color: #bbb;\n\t\t \tcolor: #333;\n\t\t\ttext-shadow: 0 1px 0\t}
\n\n\t\t.button:hover,\n\t\t.button:focus {\n\t\t\tbackground: #f3f3f3;\n\t\t\tbackground-image: -webkit-gradient
(linear, left top, left bottom, from(#fff), to(#f3f3f3));\n\t\t\tbackground-image: -webkit-linear-gradient(top, #fff,
#f3f3f3);\n\t\t\tbackground-image: -moz-linear-gradient(top, #fff, #f3f3f3);\n\t\t\tbackground-image:
-ms-linear-gradient(top, #fff, #f3f3f3);\n\t\t\tbackground-image: -o-linear-gradient(top, #fff, #f3f3f3);
\n\t\t\tbackground-image: linear-gradient(to bottom, #fff, #f3f3f3);\n\t\t\tborder-color: #999;\n\t\t\tcolor: #222;
\n\t\t}\n\n\t\t.button:focus {\n\t\t\t-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2);
\n\t\t\tbox-shadow: 1px 1px 1px rgba(0,0,0,.2);\n\t\t}\n\n\t\t.button:active {\n\t\t\toutline: none;
\n\t\t\tbackground: #eee;\n\t\t\tbackground-image: -webkit-gradient(linear, left top,
left bottom, from(#f4f4f4), to(#fefefe));\n\t\t\tbackground-image: -webkit-linear-gradient(top,
#f4f4f4, #fefefe);\n\t\t\tbackground-image: -moz-linear-gradient(top, #f4f4f4, #fefefe);
\n\t\t\tbackground-image: -ms-linear-gradient(top, #f4f4f4, #fefefe);
\n\t\t\tbackground-image: -o-linear-gradient(top, #f4f4f4, #fefefe);
\n\t\t\tbackground-image: linear-gradient(to bottom, #f4f4f4, #fefefe);
\n\t\t\tborder-color: #999;\n\t\t\tcolor: #333;\n\t\t\ttext-shadow: 0 -1px 0 #fff;
\n\t\t\t-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
\n\t\t \tbox-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );\n\t\t}\n\n\t\t\t\tbody { font-family: Tahoma, Arial; }
\n\t\t\t</style>\n</head>\n<body id=\"error-page\">\n\t<p>\u062F\u06CC\u062F\u06AF\u0627\u0647 \u062A\u06A
9\u0631\u0627\u0631\u06CC \u0634\u0646\u0627\u0633\u0627\u06CC\u06CC \u0634\u062F\u061B \u0634\u0645\u0627
\u067E\u06CC\u0634 \u0627\u0632 \u0627\u06CC\u0646 \u0647\u0645 \u0686\u0646\u06CC\u0646 \u0686\u06CC\u0632\u06CC
\u06AF\u0641\u062A\u0647 \u0628\u0648\u062F\u06CC\u062F!</p></body>\n</html>\n",
status: 500,
statusText: "Internal Server Error"
})
我知道这是错误500(“内部服务器错误”)。 我只是想知道我是否可以解析代码或至少获取html代码。 如果你仔细查看代码,你可以看到html部分:
responseText: "<!DOCTYPE html>\n<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such
that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhii
jjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqp
rqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovp
pqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9
j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono
\n-->\n<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"rtl\" lang=\"fa-IR\">\n<head>\n\t<meta http-equiv=\"Content
-Type\" content=\"text/html; charset=utf-8\" />\n\t<title>\u0648\u0631\u062F\u067E\u0631\u0633 › \u062E\u0637\
u0627</title>\n\t<style type=\"text/css\">\n\t\thtml {\n\t\t\tbackground: #f9f9f9;\n\t\t}\n\t\tbody {\n\t\t\tbackgrou
nd: #fff;\n\t\t\tcolor: #333;\n\t\t\tfont-family: sans-serif;\n\t\t\tmargin: 2em auto;\n\t\t\tpadding: 1em 2em;\n\t\t
\t-webkit-border-radius: 3px;\n\t\t\tborder-radius: 3px;\n\t\t\tborder: 1px solid #dfdfdf;\n\t\t\tmax-width: 700px;\n
\t\t}\n\t\th1 {\n\t\t\tborder-bottom: 1px solid #dadada;\n\t\t\tclear: both;\n\t\t\tcolor: #666;\n\t\t\tfont: 24px Ge
orgia, \"Times New Roman\", Times, serif;\n\t\t\tmargin: 30px 0 0 0;\n\t\t\tpadding: 0;\n\t\t\tpadding-bottom: 7px;\n
\t\t}\n\t\t#error-page {\n\t\t\tmargin-top: 50px;\n\t\t}\n\t\t#error-page p {\n\t\t\tfont-size: 14px;\n\t\t\tline-hei
ght: 1.5;\n\t\t\tmargin: 25px 0 20px;\n\t\t}\n\t\t#error-page code {\n\t\t\tfont-family: Consolas, Monaco, monospace;
\n\t\t}\n\t\tul li {\n\t\t\tmargin-bottom: 10px;\n\t\t\tfont-size: 14px ;\n\t\t}\n\t\ta {\n\t\t\tcolor: #21759B;\n\t\
t\ttext-decoration: none;\n\t\t}\n\t\ta:hover {\n\t\t\tcolor: #D54E21;\n\t\t}\n\t\t.button {\n\t\t\tdisplay: inline-b
lock;\n\t\t\ttext-decoration: none;\n\t\t\tfont-size: 14px;\n\t\t\tline-height: 23px;\n\t\t\theight: 24px;\n\t\t\tmar
gin: 0;\n\t\t\tpadding: 0 10px 1px;\n\t\t\tcursor: pointer;\n\t\t\tborder-width: 1px;\n\t\t\tborder-style: solid;\n\t
\t\t-webkit-border-radius: 3px;\n\t\t\tborder-radius: 3px;\n\t\t\twhite-space: nowrap;\n\t\t\t-webkit-box-sizing: bor
der-box;\n\t\t\t-moz-box-sizing: border-box;\n\t\t\tbox-sizing: border-box;\n\t\t\tbackground: #f3f3f3;\n\
t\t\tbackground-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4));\n\t\t\tbackground
-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4);\n\t\t\tbackground-image: -moz-linear-gradient(top, #fefefe
, #f4f4f4);\n\t\t\tbackground-image: -o-linear-gradient(top, #fefefe, #f4f4f4);\n\t\t\tbackground-image: linea
r-gradient(to bottom, #fefefe, #f4f4f4);\n\t\t\tborder-color: #bbb;\n\t\t \tcolor: #333;\n\t\t\ttext-shadow: 0 1px 0\t}
\n\n\t\t.button:hover,\n\t\t.button:focus {\n\t\t\tbackground: #f3f3f3;\n\t\t\tbackground-image: -webkit-gradient
(linear, left top, left bottom, from(#fff), to(#f3f3f3));\n\t\t\tbackground-image: -webkit-linear-gradient(top, #fff,
#f3f3f3);\n\t\t\tbackground-image: -moz-linear-gradient(top, #fff, #f3f3f3);\n\t\t\tbackground-image:
-ms-linear-gradient(top, #fff, #f3f3f3);\n\t\t\tbackground-image: -o-linear-gradient(top, #fff, #f3f3f3);
\n\t\t\tbackground-image: linear-gradient(to bottom, #fff, #f3f3f3);\n\t\t\tborder-color: #999;\n\t\t\tcolor: #222;
\n\t\t}\n\n\t\t.button:focus {\n\t\t\t-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2);
\n\t\t\tbox-shadow: 1px 1px 1px rgba(0,0,0,.2);\n\t\t}\n\n\t\t.button:active {\n\t\t\toutline: none;
\n\t\t\tbackground: #eee;\n\t\t\tbackground-image: -webkit-gradient(linear, left top,
left bottom, from(#f4f4f4), to(#fefefe));\n\t\t\tbackground-image: -webkit-linear-gradient(top,
#f4f4f4, #fefefe);\n\t\t\tbackground-image: -moz-linear-gradient(top, #f4f4f4, #fefefe);
\n\t\t\tbackground-image: -ms-linear-gradient(top, #f4f4f4, #fefefe);
\n\t\t\tbackground-image: -o-linear-gradient(top, #f4f4f4, #fefefe);
\n\t\t\tbackground-image: linear-gradient(to bottom, #f4f4f4, #fefefe);
\n\t\t\tborder-color: #999;\n\t\t\tcolor: #333;\n\t\t\ttext-shadow: 0 -1px 0 #fff;
\n\t\t\t-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
\n\t\t \tbox-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );\n\t\t}\n\n\t\t\t\tbody { font-family: Tahoma, Arial; }
\n\t\t\t</style>\n</head>\n<body id=\"error-page\">\n\t<p>\u062F\u06CC\u062F\u06AF\u0627\u0647 \u062A\u06A
9\u0631\u0627\u0631\u06CC \u0634\u0646\u0627\u0633\u0627\u06CC\u06CC \u0634\u062F\u061B \u0634\u0645\u0627
\u067E\u06CC\u0634 \u0627\u0632 \u0627\u06CC\u0646 \u0647\u0645 \u0686\u0646\u06CC\u0646 \u0686\u06CC\u0632\u06CC
\u06AF\u0641\u062A\u0647 \u0628\u0648\u062F\u06CC\u062F!</p></body>\n</html>\n"
答案 0 :(得分:3)
解析html,然后导航到目标内容。你想要p
元素中的内容吗?
alert($($.parseHTML(error.responseText)).filter("p").text());