jquery Asynchronous Request returns JSON

Source: Internet
Author: User

The first step: the front desk js Demo:

function SubmitForm () {
var hostname = $ ("#hostname"). Val ();
var port= $ ("#port"). Val ();
var validname= $ ("#validName"). Val ();
var vp= $ ("#vp"). Val ();
$.getjson ("req?Hostname= "+hostname+" &port= "+port+" &validname= "+validname+" &vp= "+VP, function (JSON) {
var ISS = json.issuccess//Front-end parsing
if (iss== "S") {
$ ("#etable"). Append ("<tr><td>" +hostname+ "</td><td>" +port+ "</td><td>" + Validname+ "</td><td>" +vp+ "</td><td>" +json.validcode+ "</td></tr>");
}
});
}

Step two: Back-end Demo:

@RequestMapping ("/main/req")
Public String Save () {
Date date = new Date ();
String hostname = this.request.getParameter ("hostname");
String port = this.request.getParameter ("port");
String validname = This.request.getParameter ("Validname");
String VP = this.request.getParameter ("VP");
String Validcode = "";
Validcode = dateformatutil.stringfromdate (date);
Validcode = Base64.encode (Validcode.getbytes ());
String savetime = dateformatutil.stringfromstanderdate (date);
String id = guid.getguid ();
Mailconfig mailconfig = new Mailconfig ();
Mailconfig.setid (ID);
Mailconfig.sethostname (hostname);
Mailconfig.setport (port);
Mailconfig.setsavetime (Savetime);
Mailconfig.setvalidcode (Validcode);
Mailconfig.setvalidname (Validname);
MAILCONFIG.SETVP (VP);
Boolean res = Mailservice.save (mailconfig);
map<string,object> returnmsg = new hashmap<string,object> ();
try {
if (res = = True) {
Returnmsg.put ("Issuccess", "S");
Returnmsg.put ("Validcode", Validcode);
this.response.getWriter (). Print (Jsonobject.fromobject (returnmsg));
}else {
Returnmsg.put ("Issuccess", "E");
This.response.getWriter (). Print (Jsonobject.fromobject (returnmsg));

}
} catch (IOException e) {
E.printstacktrace ();
}
return null;
}

jquery Asynchronous Request returns JSON

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.