简体   繁体   English

使用Ajax请求以html数据类型加载网页-错误

[英]Loading a webpage in html datatype using Ajax request - Error

I am trying to get the register numbers of the people who scored 'S' in a certain subject from a website from the localhost. 我正在尝试从本地主机的网站获取在某个主题中得分为“ S”的人员的注册号。

But i am getting this error 但是我收到这个错误

XMLHttpRequest cannot load http://sas.sastra.edu/result2013/index.php . XMLHttpRequest无法加载http://sas.sastra.edu/result2013/index.php Origin http://localhost is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用原始http://localhost

  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. 如果我不清楚,请发表评论。

Simply said http://sas.sastra.edu does not allow you to make a cross domain httprequest . 简单地说, http: httprequest不允许您进行跨域httprequest

Ajax requests are limited by the browser's Same Origin Policy. Ajax请求受浏览器的“相同来源策略”限制。 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. 这意味着您不能通过与脚本运行页面不在同一域中的ajax直接与服务器对话。因此,除非您正在为google.com开发页面,否则您无法对话直接访问google.com 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. 如果要尝试使用的API支持它们,则要么确定它们,要么尝试进行JSONP调用。

Read more about jsonp here: What is JSONP all about? 在此处阅读有关jsonp的更多信息: JSONP的全部含义是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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