简体   繁体   中英

Read XML from RSS using JavaScript

I'm trying to read a RSS from this URL http://www.vworker.com/RentACoder/misc/LinkToUs/RssFeed_newBidRequests.asp?blnAllOpen=true using JavaScript. I'm trying to XMLHttpReq to do it but its not working.

url="http://www.vWorker.com/RentACoder/misc/LinkToUs/RssFeed_newBidRequests.asp?blnAllOpen=true";
   var xmlhttp = null;
   if (window.XMLHttpRequest) 
   {
      xmlhttp = new XMLHttpRequest();
      if ( typeof xmlhttp.overrideMimeType != 'undefined') 
      {
         xmlhttp.overrideMimeType('text/xml');
      }
   } 
   else if (window.ActiveXObject) 
   {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } 
   else 
   {
      alert('Perhaps your browser does not support xmlhttprequests?');
   }

   xmlhttp.open('GET', url, true);
   xmlhttp.send(null);
   xmlhttp.onreadystatechange = function() 
   {
       if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
       {
        alert("success");
       }
       else 
       {
        alert("failure");
       }
  };

You're being limited by same origin restrictions. Could you build an intermediary (like a php script on your domain that would pull in the RSS?) then you'd change your url to that script

<?php
$x=file_get_contents('http://www.vworker.com/RentACoder/misc/LinkToUs/RssFeed_newBidRequests.asp?blnAllOpen=true');
echo $x;
 ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM