Ajax cross-domain requests, page and Java service-side notation

Source: Internet
Author: User

Page Ajax Request Syntax:

$.ajax ({type: "Get", Async:false,cache:false,url: "http://localhost:8081/a/b", data: {produ_id:111,sub_id:0,produ_q Uantity:1,produ_price:0.0},datatype: "Jsonp", Jsonp: "Jsonpcallback", success:function (data) {var d = Data;alert (d);}, Error:function () {alert (' fail ');}});

  

Java service-side notation:

public void Ajaxrequest (params params) {HttpServletRequest request =; HttpServletResponse response =; Response.setcontenttype ("Text/plain"); Response.setheader ("Pragma", "No-cache"); Response.setheader ("Cache-control", "No-cache"); Response.setdateheader ("Expires", 0); map<string, string> map = new hashmap<string, string> (); Map.put ("Result", "content"); PrintWriter out = null;try {out = Response.getwriter (); String jsonstring = jsonobject.tojsonstring (map);//Use whichever jsonobject you want, just go to JSON-formatted string jsonpcallback = Request.getparameter ("Jsonpcallback");//Client request parameter Out.println (Jsonpcallback + "(" + jsonstring + ")");//return JSONP format data} catch (IOException e) {e.printstacktrace ();} finally{out.flush (); Out.close ();}}

  

Ajax cross-domain requests, page and Java service-side notation

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.