jquery ajax readystate 0 responsetext status 0 stext错误
I am getting the following error: jquery ajax readystate 0 responsetext status 0 statustext error
when giving it: url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm)
, however it's working fine when I give it url(localhost:""/embparse_page)
on my localhost.
我得到了以下错误:jquery ajax readystate 0 responsetext status 0在给出url时出现了:url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm),但是当我在本地主机上给它url(localhost:""/embparse_page)时,它工作得很好。
I have tried using the headers which I found on a Google search, and I have used beforeSend:""
too, but it's still not working.
我尝试过使用在谷歌搜索中找到的标题,我也使用了前面的“”,但是它仍然不能工作。
I think the main problem is: XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin "local server" is not allowed by Access-Control-Allow-Origin.
but I don't understand it.
我认为主要的问题是:XMLHttpRequest不能加载http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm。访问控制允许的源不允许“本地服务器”。但我不明白。
Can anyone please explain the problem to me, as I'm quite new to this.
谁能给我解释一下这个问题,因为我对这个问题很陌生。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ng="http://angularjs.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta Access-Control-Allow-Origin="*" />
<title>Page Parsing</title>
<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
<script>
getit=function(){
jQuery.support.cors = true;
$.ajax({
type:"GET",
url:"http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm",
dataType:"html",
crossDomain:true,
beforeSend: function(xhr) {
xhr.overrideMimeType('text/plain;charset=UTF-8');
},
success:function(XMLHttpRequest,jqXHR ,data) {
//alert(data.title);
var starttitl=data.lastIndexOf('<title>');
var endtitl=data.lastIndexOf('</title>');
var title1=data.substring(starttitl+7,endtitl);
alert(title1);
},
error:function(errorStatus,xhr) {
alert("Error"+JSON.stringify(errorStatus));
}
});
}
</script>
</head>
<body>
<div id="siteloader">
<input type="button" onclick="getit()" />
</div>
</body>
</html>
4 个解决方案
#1
18
I was getting this error and in my case it was not due to same origin policy. I got some help from this link
我犯了这个错误,在我的例子中这不是由于相同的原产地政策。我从这个链接中得到了一些帮助
My case was, I had a link button and I was not using e.PreventDefault()
我的情况是,我有一个链接按钮我没有使用e。preventdefault ()
ASPX
ASPX
<asp:LinkButton ID="lnkSearch" runat="server" CssClass="DockCmdSearch" CommandName="Search" OnClientClick="return VerifySearch(this, event);" />
Javascript
Javascript
function VerifySearch(sender, e) {
e.preventDefault();
$.ajax({
type: 'POST',
.............
}
return false;
}
更多相关文章
- 为什么我收到此错误:“未捕获的TypeError:无法读取未定义的属性'标
- 如何避免pro拖拉机中的“jasmin .suite() required”错误消息?
- “错误:路径必须是字符串”(v5.10.0)
- 使用bootstrap模式框的自定义选择框错误
- element.replaceWith在自定义指令的链接中仅在第一次调用时工作
- $.each遍历JSON字符串和 Uncaught TypeError: Cannot use 'in' o
- 2_python连接MariaDB错误
- 获取错误“ValueError:int()的无效文字,基数为10:'3128;'在运行Tensor
- GIS / Gdal / OSGeos在Windows上的django中导入错误