0

I am trying to get the register numbers of the people who scored 'S' in a certain subject from a website from the localhost.

But i am getting this error

XMLHttpRequest cannot load http://sas.sastra.edu/result2013/index.php. Origin http://localhost is not allowed by Access-Control-Allow-Origin

  for(i=115003001;i<115003230;i++)
{
    $.post("http://sas.sastra.edu/result2013/index.php",{regno:i},function(data,textstatus,obj){
        if($(data).find('tbody tr:nth-child(2) td:nth-child(2)').text().slice(60,62)=="S")
        {
            console.warn(i);
        }
    },{dataType:"HTML"});
}

Please Comment if i am not clear.

Usual Suspect
  • 601
  • 1
  • 8
  • 19

1 Answers1

1

Simply said http://sas.sastra.edu does not allow you to make a cross domain httprequest.

Ajax requests are limited by the browser's Same Origin Policy. This means that you can't talk directly to a server via ajax that isn't on the same domain as the page your script is running in. So, unless you're developing a page for google.com, you can't talk to google.com directly httprequest.

Making Either make sure they though or try doing a JSONP call is probably what you need to do here if the API you're attempting to use supports it.

Read more about jsonp here: What is JSONP all about?

Community
  • 1
  • 1
Timmetje
  • 7,641
  • 18
  • 36