Ajax detailed parameter use cases in jquery

Source: Internet
Author: User
Tags browser cache

Ajax detailed parameter use cases in jquery

Reference Document: http://www.jb51.net/shouce/jquery1.82/
Reference Document: Http://jquery.cuishifeng.cn/jQuery.Ajax.html

Precautions

This case demo tests the use of infrequently used parameters in official documents

Front-end Code
 function thefileuploadgai() {//Perform upload     varzhi={"A1":["Hello.","こんにちは","Hello"],"A2":["November 1, 2017",true],"A3":"false","A5":[ -,"Teststr"]     };//Manually generate a JSON-formatted object note keys must have quotation marks     /** Jquery Reference API version 1.8.2*/     the/** jqxhr object is a XMLHttpRequest object that jquery itself forged and $. Deferred object's binding reference http://www.365mini.com/page/jquery-jqxhr-object.htm*/$.ajax ({URL:"Downparajson.do",//Absolute address/relative addressType' POST ',//No garbledData:zhi,//data sent to the server JS-enabled object/string will be automatically converted to the request string format. But the GET request will be appended to the URLAsyncfalse,//Enable synchronizationCachefalse,//Do not use browser cache for each request         //datatype: "JSON",//expected server to return data type XML HTML script JSON Jsonp textBeforesend: function(JQXHR){//Can I modify the XMLHttpRequest object before sending the request? data processingConsole.log ("beforesend msg: processing data before sending request");if(1<2) {Console.log ("Beforesend Judge Xhr object:"+ (JQXHRinstanceofXMLHttpRequest) +"and print JQXHR");//FalseConsole.log (jqxhr.readystate+" "+ jqxhr.status+" "+//Return HTTP status codes, such as common 404,500 error codes. jqxhr.statustext+" "+//error message corresponding to the status code,Jqxhr.responsetext);//The text message returned by the server response                 return true; }Else{return false;}//return False to cancel this Ajax request}, Datafilter: function (dataoriginal, type) { //preprocessing the original data returned by Ajax type refers to the value above datatype:Console.log ("Datafilter msg: The raw data returned by the server is now being processed");if(type=="JSON"){//Note dataoriginal is always the string that must be converted again to the string system to process again                //console.log (typeof dataoriginal);//string                varjsobj=JSON. Parse (dataoriginal); jsobj["NewData"]=["New",true,10000];varZhi=JSON. stringify (Jsobj);returnZhi }returndataoriginal;//Return to processed data}, Success: function (DATA,TEXTSTATUS,JQXHR) {The value of//status is "success"Console.log (JSON. stringify (Data,NULL,4)+" "+ jqxhr.readystate+" "+ jqxhr.status+" "+//Return HTTP status codes, such as common 404,500 error codes. jqxhr.statustext+" "+//error message corresponding to the status code,Jqxhr.responsetext +" "+//The text message returned by the server responseTextstatus);//console.log (data. DATALIST2[1]);//Can parse JSON directlyConsole.log (' success msg: successful after request '); }, Error: function (jqxhr,textstatus,errorthrown) {The value of//error is "error" can be triggered with the wrong link addressConsole.log (jqxhr.readystate+" "+ jqxhr.status+" "+//Return HTTP status codes, such as common 404,500 error codes. jqxhr.statustext+" "+//The error message corresponding to the status code, such as the 404 error message is not found,500 is internal Server error. Jqxhr.responsetext +" "+//The text message returned by the server responsetextstatus+" "+//Indicates that the returned status string may be "timeout" except NULL, "error", "Notmodified", "ParserError" parsing exception, "Abort" abortedErrorthrown);//Indicates that the server throws the returned error message stringConsole.log (' ERROR msg: Errors occurred after request '); }, statuscode:{//A set of numeric HTTP codes and function objects, when the corresponding code is called when responding            404: function() {Console.log (' statusCode 404:404 Errors reported ');}, $: function() {Console.log (' StatusCode 200: request succeeded ');} },//Not usedComplete function (JQXHR, Textstatus) {//After the request is complete, the callback function succeeds/failsConsole.log (jqxhr.readystate+" "+ jqxhr.status+" "+//Return HTTP status codes, such as common 404,500 error codes. jqxhr.statustext+" "+//The error message corresponding to the status code, such as the 404 error message is not found,500 is internal Server error. Jqxhr.responsetext +" "+//The text message returned by the server responseTextstatus);//Indicates the returned status string "Success"}, headers:{"Sysversion":"ios10.0"},//An additional "{Key: Value}" to map to the request sent together this setting is set before the Beforesend function is called        //contenttype: "application/x-www-form-urlencoded",//Send information to the server when the content encoding type Plus this will append to the URL after the link garbledTimeout60000,//Set Request time-out (ms) 60000 ms =60 secUsername"Wang",//user name used in response to HTTP access authentication requestPassword"12345678",//password in response to HTTP access authentication request});}
Background code
@RequestMapping("Downpara.do") Public void Downpara(HttpServletRequest request,httpservletresponse response)throwsioexception{Map Map=request.getparametermap ();The //API document is written in <string, string[]> typeiterator<entry<string, string[]>> entries = Map.entryset (). Iterator (); String aa=""; while(Entries.hasnext ())          {entry<string, string[]> Entry = Entries.next (); String bb="  "+entry.getkey () +"="+ commonutils.tostring (Entry.getvalue (),"");          System.out.println (BB);    AA=AA+BB; }//system.out.println (Map.containskey ("A1")); False    //system.out.println (Map.containskey ("a1[)");//trueResponse.setcontenttype ("Text/html;charset=utf-8"); Response.getwriter (). write (AA);}/** Asynchronous upload parameter return JSON string * /@RequestMapping("Downparajson.do") Public void Downparajson(HttpServletRequest request,httpservletresponse response)throwsioexception{Map Map=request.getparametermap ();The //API document is written in <string, string[]> typeiterator<entry<string, string[]>> entries = Map.entryset (). Iterator (); String aa=""; while(Entries.hasnext ())          {entry<string, string[]> Entry = Entries.next (); String bb="  "+entry.getkey () +"="+ commonutils.tostring (Entry.getvalue (),"");          System.out.println (BB);    AA=AA+BB; } SimpleDateFormat Dateformater =NewSimpleDateFormat ("Yyyy-mm-dd"); Jsonobject jsonall=NewJsonobject (); Jsonall.put ("ReturnValue",0); Jsonall.put ("MSG","parameter is correct"); Jsonarray jsonarr=NewJsonarray (); Object[] Shuzu=Newobject[]{"College English","2016-09-09", +,false}; Jsonall.put ("Datalist2", Jsonarr.fromobject (Shuzu)); Response.setcontenttype ("Application/json;charset=utf-8"); Response.getwriter (). Write (jsonall.tostring ());}
case where the test result return type is JSON

Url= "Downparajson.do"

Case where the return type is a string

Url= "Downpara.do"

Ajax detailed parameter use cases in jquery

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.