The traditional parameter pass of the JQuery $.ajax Pass array must be True__javascript

Source: Internet
Author: User


At first I think Traditional:true, dispensable, but later do not need to traditional, found that the background can not get the selectusers value, then it is certain that the traditional default value is False.
When the submitted parameter is an array ({Selectusers:[value,value,value]}), if False, the commit is "Selectusers[]=value&selectusers[]=value"
If set to true, the commit will be "selectusers=value&selectusers=value"
So backstage can use string[] ids=request.getparametervalues ("selectusers"); Gets the value.




The official documentation is explained as follows:
Traditional
Type: Boolean
If you want to serialize data in a traditional way, set it to true.
Set this to true if your wish to use the traditional style of Param serialization


One: Front desk jquery
DeleteAll () {

var selectusers=new Array ();
var selectusers = null;
$ (": Checkbox[name= ' UserID ']"). each (function () {


if ($ (this). attr ("checked"))
Selectusers.push ($ (this). Val ());
Selectusers + = "," + $ (This). Val ();
})


alert (selectusers);

$.ajax ({
Async:false,
Traditional:true,
Type: "Post",
URL: "Elecuseraction_delete.do",
Data:{selectusers:selectusers},

/* Success:function (Responstext) {
if (responstext== "1") {
Alert ("Delete succeeded");
}

} */



});
}
Two: Background action code
Public String Delete () {
Actioncontext Context=actioncontext.getcontext ();
HttpServletRequest request= (httpservletrequest) context.get (servletactioncontext.http_request);

String[] Ids=request.getparametervalues ("selectusers");

System.out.println (Ids.tostring ());
PrintWriter out = null;
Out.write ("1");

return home ();
}






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.