Request load file Data
var loadfile=function () {
$.ajax ({
URL: ' filepreview.do ',
data:{' ID ': ID, ' MD5 ': MD5},
type: ' Post ',
dataType: ' json ',
Cache:false,
success:function (data) {
switch (data.statuscode ) {Case
0: Case
1: Case
2: Case
3:
alert (' 3 ');
Reloadfile ();
break;
Case 4:
alert (' 4 ');
Showfile (data);
break;
Case-1:
alert ('-1 ');
Showfailed ();
break;
Default:
showfailed ();
}
,
error:function (data) {
alert (' Error ');
Background return:
<ol tabindex= "0" class= "outline-disclosure" style= "Font:12px/normal ' Segoe UI ', Tahoma, Sans-serif; margin:0px; Color:rgb (34, 34, 34);
Text-transform:none; text-indent:0px; Letter-spacing:normal; word-spacing:0px; List-style-type:none; White-space:normal; Box-sizing:border-box;
Font-size-adjust:none; Font-stretch:normal; Background-color:rgb (255, 255, 255); -webkit-padding-start:12px; -webkit-text-stroke-width:0px; " >
<li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; -ms-word-wrap:break-word; Box-sizing:border-box; " >
<div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >
remote address:</div>
<div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px;
Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >[::1]:8080</div>
</li><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; -ms-word-wrap:break-word; Box-sizing:border-box; " >
<div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >
request url:</div><div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em;
Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >http://localhost:8080/file_preview/filepreview.do</div></li>
<li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; -ms-word-wrap:break-word; Box-sizing:border-box; " >
<div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >
request method:</div><div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em;
Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >post</div>
</li><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; -ms-word-wrap:break-word; Box-sizing:border-box; " >
<div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >
status code:</div><div title= "$ OK" class= "Resource-status-image green-ball" style= " Background-position: -235px-96px; width:10px; height:10px; Margin-top: -2px; margin-right:3px;
Vertical-align:middle; Display:inlinE-block; Box-sizing:border-box; Background-image:url (' chrome-devtools://devtools/bundled/images/statusbarbuttonglyphs.png ');
background-size:320px 144px; " ></div><div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px;
Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >200 ok</div></li>
<li title= "" class= "parent Expanded" style= "padding:0px 0px 0px 14px; Font-weight:bold; margin-top:1px; Margin-left: -12px; -ms-word-wrap:break-word;
Box-sizing:border-box; -webkit-user-select:none; " >request headers<span class= "header-toggle" style= "color: #737373; font-weight:normal; margin-left:30px;
Display:inline; Box-sizing:border-box; " >view parsed</span></li><ol class= "Children expanded" style= "margin:0px; padding:2px 6px!important; Display:block; List-style-type:none;
position:relative; Cursor:default; min-width:100%; Box-sizing:border-box; -webkit-padding-start:12px; " ><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px;
White-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " ><span class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace;
font-size: 12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >
post/file_preview/filepreview.do http/1.1host:localhost:8080connection:keep-alivecontent-length:72accept: Application/json, Text/javascript, */*; q=0.01origin:http://localhost:8080x-requested-with:xmlhttprequestuser-agent:mozilla/5.0 (Windows NT 6.2; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/39.0.2171.99 safari/537.36 lbbrowsercontent-type:application/ X-www-form-urlencodedreferer:http://localhost:8080/file_preview/apply.doaccept-encoding:gzip, Deflateaccept-languAge:zh-cn,zh;q=0.8cookie:jsessionid=84bbee2a60f765b810cffbec145de240</span></li></ol><li Title= "" class= "parent Expanded" style= "padding:0px 0px 0px 14px; Font-weight:bold; margin-top:1px; Margin-left: -12px; -ms-word-wrap:break-word; Box-sizing:border-box; -webkit-user-select:none; " >form data<span class= "header-toggle" style= "color: #737373; font-weight:normal; margin-left:30px; Display:inline; Box-sizing:border-box; " >view source</span><span class= "header-toggle" style= "color: #737373; font-weight:normal; margin-left:30px; Display:inline; Box-sizing:border-box; " >view URL encoded</span></li><ol class= "Children expanded" style= "margin:0px; padding:2px 6px!important; Display:block; List-style-type:none; position:relative; Cursor:default; min-width:100%; Box-sizing:border-box; -webkit-padding-start:12px; " ><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; White-space:nowraP -ms-word-wrap:break-word; Box-sizing:border-box; " ><div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >id:</div><div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace ; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >b6de6638253943a19890ac4f9dd2587c</div></li><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; White-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " ><div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >md5:</div>
<div class= "Header-value source-code"
style="Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >de2f59c0cec5ce16ae84b74d7a3af046</div></li></ol><li title= "" class= "parent Expanded" style= "padding:0px 0px 0px 14px; Font-weight:bold; margin-top:1px; Margin-left: -12px; -ms-word-wrap:break-word; Box-sizing:border-box; -webkit-user-select:none; " >response headers<span class= "header-toggle" style= "color: #737373; font-weight:normal; margin-left:30px; Display:inline; Box-sizing:border-box; " >view source</span></li><ol class= "Children expanded" style= "margin:0px; padding:2px 6px!important; Display:block; List-style-type:none; position:relative; Cursor:default; min-width:100%; Box-sizing:border-box; -webkit-padding-start:12px; " ><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; WhitE-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " ><div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >content-length:</div><div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >675</div></li><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; White-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " ><div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >content-type:</div><div class= "Header-value source-code"Style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >application/json;charset=utf-8</div></li><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; White-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " >
<div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em;
Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >date:</div>
<div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace;
FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >
wed, June 09:11:02 gmt</div></li><li title= "style=" padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px; White-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " ><div class= "Header-name" style= "Color:rgb (84, 84, 84); Font-weight:bold; Margin-right:0.5em; Vertical-align:top; Display:inline-block; White-space:pre-wrap; Box-sizing:border-box; " >server:</div><div class= "Header-value source-code" style= "Font-family:consolas, ' Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; White-space:pre-wrap; -ms-word-break:break-all; Box-sizing:border-box; " >apache-coyote/1.1</div></li></ol><li title= "" style= "padding:0px 0px 0px 14px; margin-top:1px; Margin-left: -2px;
White-space:nowrap; -ms-word-wrap:break-word; Box-sizing:border-box; " ><div class= "Header-value source-code" style= "Font-family:consolas, '
Lucida Console ', monospace; FONT-SIZE:12PX!important; margin-top:1px; Margin-right:1em; Display:inline; white-space:pre-Wrap -ms-word-break:break-all; Box-sizing:border-box; " >
</div></li></ol><ol tabindex= "0" class= "outline-disclosure" style= "font:12px/ Normal ' Segoe UI ', Tahoma, Sans-serif; margin:0px; Color:rgb (34, 34, 34); Text-transform:none;
text-indent:0px; Letter-spacing:normal; word-spacing:0px; List-style-type:none; White-space:normal; Box-sizing:border-box; Font-size-adjust:none;
Font-stretch:normal; Background-color:rgb (255, 255, 255); -webkit-padding-start:12px; -webkit-text-stroke-width:0px; " >
Status 200; But the alert is error;</ol>.
How to resolve:
1. The data type to be returned must conform to the defined data type. That is, if the dataType you define is a JSON type, the returned data must be JSON, flat and otherwise the block of error will be executed.
(1) It is also necessary to pay special attention to whether the JSON data returned is a strict JSON format.
(2) It should also be a serious concern that when the back of a list data is returned (the data in the list is in JSON format), there is no dirty data that is not a strict JSON format.
It could be subtle. A field in the data contains special characters at the beginning or end, with "Enter", "tab", etc.
The evasion of such covert errors is good programming habits:
A. For the data to fill in the storage of the best mandatory to do, go empty operation < Use the client best >.
B. Special services need to be aware of special characters.
This is not enough, because in the development process of testing or developers to manually add data in the database, there may be extra space, etc., resulting in program debugging, testing brings trouble. At this point, you need to consider in the background code to get the data processed.
2. The reason is that the Ajax request cross-domain, the solution is to add a section of JS in two files: [/b]document.domain, or the use of JSONP, as mentioned in my previous blog.
There is a little bit of Ajax in the other understanding of the other: the client initiated the request, the server side of the corresponding is 200,< correctly get the server response to the data > no problem. At this point in judgment into success The corresponding callback function may check something before it enters the callback function that corresponds to the error:
1. Whether each data returned is a data type defined in datatype. If some of the data is not or even if a piece of data is not strictly defined by datatype, the program goes to Error:function () {* *}
2. Whether the requested domain and the current domain are the same domain, and if not the same domain, it is very likely to enter error:function () {* *} "