ASP.NET中MVC使用AJAX调用JsonResult方法并返回自定义错误信息(4)
复制代码 代码如下: span class="pln"$span class="pun".span class="pln"ajaxspan class="pun"({span class="pln" urlspan class="pun":span class="pln" span class="str""/Fuck/FuckJson"span class="pun
复制代码 代码如下:
<span class="pln">$<span class="pun">.<span class="pln">ajax<span class="pun">({<span class="pln">
url<span class="pun">:<span class="pln"> <span class="str">"/Fuck/FuckJson"<span class="pun">,<span class="pln">
data<span class="pun">:<span class="pln"> <span class="str">""<span class="pun">,<span class="pln">
dataType<span class="pun">:<span class="pln"> <span class="str">"json"<span class="pun">,<span class="pln">
type<span class="pun">:<span class="pln"> <span class="str">"POST"<span class="pun">,<span class="pln">
contentType<span class="pun">:<span class="pln"> <span class="str">"application/json; charset=utf-8"<span class="pun">,<span class="pln">
dataFilter<span class="pun">:<span class="pln"> <span class="kwd">function<span class="pln"> <span class="pun">(<span class="pln">data<span class="pun">)<span class="pln"> <span class="pun">{<span class="pln">
<span class="kwd">return<span class="pln"> data<span class="pun">;<span class="pln">
<span class="pun">},<span class="pln">
success<span class="pun">:<span class="pln"> <span class="kwd">function<span class="pln"> <span class="pun">(<span class="pln">data<span class="pun">)<span class="pln"> <span class="pun">{<span class="pln">
alert<span class="pun">(<span class="pln">data<span class="pun">);<span class="pln">
<span class="pun">},<span class="pln">
error<span class="pun">:<span class="pln"> <span class="kwd">function<span class="pln"> <span class="pun">(<span class="pln">fuckedObject<span class="pun">)<span class="pln"> <span class="pun">{<span class="pln">
<span class="kwd">try<span class="pln"> <span class="pun">{<span class="pln">
<span class="kwd">var<span class="pln"> json <span class="pun">=<span class="pln"> $<span class="pun">.<span class="pln">parseJSON<span class="pun">(<span class="pln">fuckedObject<span class="pun">.<span class="pln">responseText<span class="pun">);<span class="pln">
alert<span class="pun">(<span class="pln">json<span class="pun">.<span class="pln">errorMessage<span class="pun">);<span class="pln">
<span class="pun">}<span class="pln"> <span class="kwd">catch<span class="pun">(<span class="pln">e<span class="pun">)<span class="pln"> <span class="pun">{<span class="pln">
alert<span class="pun">(<span class="str">'something bad happened'<span class="pun">);<span class="pln">
<span class="pun">}<span class="pln">
<span class="pun">}<span class="pln">
<span class="pun">})</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
现在请求这个Action,会发现Response的状态已经是500了。并且返回了Json格式的错误信息。
收藏文章
精彩图集
精彩文章