JavaScript and Ajax cross-domain access implementations

Source: Internet
Author: User
Tags script tag

One, JavaScript cross-domain access

1. Set the Document.domain value of the access page and the page being visited.

2, use the IFRAME to connect two domains of the page.

II. Ajax cross-domain access

1, using the script tag to achieve

The implementation example has two pages a.b.com/source.jsp, c.d.com/target.jsp, where the target.jsp page is accessed in the Source.jsp page

The code is as follows:

source.jsp

<mce:script type= "Text/javascript" id= "Geturl" "src=" "></mce:script> <mce:script type=" text/ JavaScript "><!--function Fungetotherdomain () {var obj = document.getElementById (" Geturl "); obj.src=" http:// C.d.com/target.jsp "; alert (obj.readystate); alert (XML); if (obj.readystate== "loaded") {alert (jsonobject.name); alert (jsonobject.address);}} --></mce:script>

target.jsp

<% @page import= "net.sf.json.*,java.util.*"%> <% map map = new Linkedhashmap (); Map.put ("name", "AAAA"); Map.put ("Address", "bbbb"); Jsonobject jsonobject = jsonobject.fromobject (map); Out.println ("var jsonobject=" +jsonobject); %>

2. Web Proxy method

Use HttpClient to get page information.

3, the way of the IFRAME

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.