JSONP Processing cross-domain

Source: Internet
Author: User

1. Page request

function complete () {
var data = {
"enterprise_id": "8316",
"Receiver_name": "Wang Min",
"Province_code": "110000",
"City_code": "110100",
"District_code": "110102",
"Province_name": "Beijing",
"City_name": "Municipal districts",
"District_name": "Xicheng District",
"Address": "Here is the detailed addresses",
"Contact_phone": "18721703659",
"default_address": "0"
};
$.ajax ({
Url:ctx + "/enterpriseinfo/savereceiveraddress",
Type: "POST",
Data:JSON.stringify (data),
DataType: ' JSONP ',
JSONP: "Callbacksaveaddress",
Jsonpcallback: "Success_jsonp",
ContentType: "Application/json",
Success:function (data) {
Console.info (data);
}
});

var data = {
"enterprise_id": "8316",
"Receiver_name": "Wang Min",
"Province_code": "110000",
"City_code": "110100",
"District_code": "110102",
"Province_name": "Beijing",
"City_name": "Municipal districts",
"District_name": "Xicheng District",
"Address": "Here is the detailed addresses",
"Contact_phone": "18721703659",
"default_address": "0"
};
$.ajax ({
URL: "Http://usermanage.yaoex.com:8080/enterpriseInfo/saveReceiverAddress",
Data:data,
DataType: ' JSONP ',
JSONP: "Callbacksaveaddress",
Jsonpcallback: "Success_jsonp",
ContentType: "Application/json;charset=utf-8",
Success:function (data) {
Console.info (data);
}
});
}

2. Server response

/**
* New increase shipping address information
* @return
* @throws Exception
* {"enterprise_id": "8316", "Receiver_name": "Little Cai", "Province_code": "110000", "City_code": "110100", "District_code": "110102", "Province_name": "Beijing", "City_name": "City District", "District_name": "Xicheng", "Address": "Here is the detailed addresses", "Contact_phone": " 18721703659 "," default_address ":" 0 "}
*/
@RequestMapping (value = "/savereceiveraddress")
@ResponseBody
Public String savereceiveraddress (httpservletrequest request, @RequestBody usermanagereceiveraddress usermanagereceiveraddress) {
String jsonpcallback = Request.getparameter ("callbacksaveaddress");
Map<string, object> resp = new hashmap<string, object> ();
try {
Get user Information
User user = Usermanageuserutil.getcurrentuser (request);
if (null = = user) {
Resp.put ("Result", "error");
Resp.put ("msg", "Failed to get login user information properly!");
Logger.info ("Failed to get login user information properly!");
return jsonpcallback + "(" + jsonobject.tojsonstring (RESP) + ")";
}
USERMANAGERECEIVERADDRESS.SETENTERPRISE_ID (String.valueof (user.getenterprise_id ()));
List<usermanagereceiveraddress> usermanagereceiveraddresslist= Usermanageenterpriseservice.queryreceiveraddress (String.valueof (user.getenterprise_id ()));
if (null! = Usermanagereceiveraddresslist && usermanagereceiveraddresslist.size () >=10) {
Resp.put ("Result", "error");
Resp.put ("MSG", "Add failed, you can only save 10 shipping address information!");
Logger.info ("Add failed, you can only save 10 shipping address information!");
return jsonpcallback + "(" + jsonobject.tojsonstring (RESP) + ")";
}
Add address insert Formal table
Usermanageenterpriseservice.saveaddress (usermanagereceiveraddress);
Resp.put ("Result", "success");
Resp.put ("MSG", "Address saved successfully!");
return jsonpcallback + "(" + jsonobject.tojsonstring (RESP) + ")";
} catch (Exception e) {
Logger.error (E.getmessage ());
Resp.put ("Result", "error");
Resp.put ("MSG", "Address save failed!");
return jsonpcallback + "(" + jsonobject.tojsonstring (RESP) + ")";
}
}

JSONP Processing cross-domain

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.