Use Ajax cross-origin to read RSS-use Ajax proxy to solve Ajax cross-origin problems

Source: Internet
Author: User
In ie, the message shown is displayed every time RSS is read. In Firefox, RSS is not read at all.

{
Img_auto_size (this, 450, true );
} "Align =" baseline "twffan =" done "src =" http://esoft.bokee.com/inc/AJAXProxy1.jpg ">

This is because AJAX can only access resources in the current domain, rather than cross-origin access, based on security considerations. That is to say, Ajax in the domain1.com site can only access resources under the domain1.com site, but cannot access resources in the domain2.com site across domains. This is the cross-origin issue of Ajax.

There are several methods to solve Ajax cross-origin problems. Here we only discuss one of the most common methods-use Ajax proxy to solve Ajax cross-origin problems. that is, dynamic web pages (Asp, PHP, JSP, etc.) are used as proxy pages in the domain1.com site to read Resources in the domain2.com site, and then the agent pages in the domain1.com site are read using Ajax. take ASP as an example to introduce Ajax Proxy:

 

 

Ajax proxy --- ASP (JavaScript)

Ajaxproxy. asp

  1. <% @ Language = "JavaScript" codePage = "936" %>
  2. <%
  3. VaR http1 = server. Createobject ("Microsoft. XMLHTTP ");
  4. VaR rss_url = request ("rss_url ");
  5. Http1.open ("get", rss_url, false );
  6. Response. contenttype = "text/XML ";
  7. Http1.send (null );
  8. If (http1.readystate = 4 ){
  9. Response. binarywrite (http1.responsebody );
  10. }
  11. Http1 = NULL;
  12. %>

 

Ajax proxy --- ASP (VBScript)

Ajaxproxy. asp

  1. <% @ Language = "VBScript" codePage = "936" %>
  2. <%
  3. Function send_request (URL)
  4. Set retrieval = Createobject ("Microsoft. XMLHTTP ")
  5. With Retrieval
  6. . Open "get", URL, false ,"",""
  7. . Send
  8. Send_request =. responsebody
  9. End
  10. Response. contenttype = "text/XML"
  11. Set retrieval = nothing
  12. End Function
  13. Url = request ("rss_url ")
  14. Response. binarywrite send_request (URL)
  15. Response. Flush
  16. %>

Http://developer.yahoo.com/javascript/howto-proxy.html

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.