The jquery Ajax request returns Boolean and object, traversing the object

Source: Internet
Author: User

HTML code:

<Tr>
<TD> <FMT: Message key = "ttesbill. cusomerid"/> </TD>
<TD> <select name = "cusomerid" class = "cusomerid" style = "width: 165px">
<Option> --- Select --- </option>
<C: foreach items = "$ {banklist}" Var = "banklist">
<Option value = "$ {banklist. cusomerid}" >$ {banklist. customername} |$ {banklist. cardno} </option>
</C: foreach>
</SELECT>
</Tr>

Jquery code:

$ ("Select [name = 'cusomerid']"). Change (function (){

VaR cusomerid = $ ("option: Selected", this). Val (); // get the drop-down box Value

$. Ajax ({
Type: "Post", // use post to submit a request
URL: "$ {CTX}/ttesbillcontroller. do? Method = getcusomer ", // submit the URL
Data: "cusomerid =" + cusomerid, // submit Parameters
Success: function (data, status) {// process the returned Function
If (status = "success") {// confirm the return value
For (var p in data) // cyclically traverses an object
$ ("Input [name =" + P + "]"). Val (data [p]); // fill in the HTML text box
}
},
Error: function (){
Alert ("an error occurred... your operation is incorrect ");
}
});
});

Java code:

Public modelandview getcusomer (httpservletrequest request,
Httpservletresponse response ){
String cusomerid = request. getparameter ("cusomerid ");
Tbankcustomer tbank = tbankcustomerservice. gettbankcustomerbyid (cusomerid );
Renderjson (response, jsonutil. tostring (tbank, jsonutil. collection_filter ));
// Return object, no need to convert
Return NULL;
}

Returns a Boolean value in JSON format.

Renderjson (response, tojson ("success", flag ));

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.