Mui.ajax and Server (SPRINGMVC) transfer JSON data

Source: Internet
Author: User

cross-domain issues

PC-side for security, so cross-domain is prohibited. When I use MUI as a mobile web, I will inevitably use my PC browser for debugging. Mui.ajax is allowed across domains. In order to be able to debug successfully, the browser needs to be set and. For example, the 360 haste browser is set up as follows:

  

Add--disable-web-security (preceded by a space) after the target

front-end settings

  

<script type= "Text/javascript" charset= "UTF-8" >    reginfo = {name: ' Wuchao ', Password: ' 000111 '};     Mui.ajax (' http://localhost:8080/share/mobile/regist.do ', {data:JSON.stringify (Reginfo), DataType: ' JSON ',// The server returns JSON format data contenttype: "Application/json", type: ' Post ',//http request type timeout:10000,//timeout set to 10 seconds; headers:{' Content-type ': ' Application/json '},              success:function (data) {//server returns a response, based on the response result, analyzes whether the login succeeded; alert (Data.result);}, Error:function (Xhr,type,errorthrown) {//exception handling; alert ("error");},headers: {' access-control-allow-headers ': ' X-requested-with '}});</script>

  

back-end settings

  Requires three jar packages, Jackson-annotations-2.7.0.jar Jackson-core-2.7.0.jar Jackson-databind-2.4.5.jar (version is selected as 2.4.5 should be available, but DataBind package selected as 2.7.0 will error) click here.

The controller is as follows:

  

@RequestMapping (value = "/mobile/regist", method=requestmethod.post,produces = "Application/json;charset=utf-8") Public @ResponseBody Modelandview Handle4mobile (@RequestBody  info info) {System.out.println (Info.getname ()); map<string, string> map = new hashmap<string, string> (); Map.put ("Result", "sucess"); return new Modelandview (New Mappingjackson2jsonview (), map);}

where the info class corresponds to the front-end incoming JSON data. The data returned corresponds to the callback function of the front-end success.

Mui.ajax and Server (SPRINGMVC) transfer JSON data

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.