问题描述
我收到以下错误: jQuery的AJAX readystate为0 responseText的状态0状态文本错误
给时: URL(HTTP:// WWW。 tutorialspoint.com/prototype/prototype_ajax_response.htm)
,但它的正常工作,当我给它 URL(本地主机:/ embparse_page)
我本地主机。
我已经用我发现在谷歌搜索标题尝试过了,我已经使用 beforeSend:
过,但它仍然无法正常工作
我觉得主要的问题是: XMLHtt prequest无法加载http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm。起源本地服务器没有被访问控制 - 允许 - 产地允许的。
,但我不明白。
任何人都可以请解释这个问题给我,因为我很新的这一点。
<!DOCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-transitional.dtd>
< HTML的xmlns:NG =http://angularjs.org>
< HEAD>
< META HTTP-当量=Content-Type的CONTENT =text / html的;字符集= ISO-8859-1/>
<荟萃访问控制 - 允许 - 原产地=*/>
<标题>页面解析< /标题>
<脚本类型=文/ JavaScript的SRC =/ JS / jQuery的-1.9.1.min.js>< / SCRIPT>
<脚本>
GETIT =功能(){
jQuery.support.cors = TRUE;
$阿贾克斯({
键入:GET,
网址:http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm
数据类型:HTML,
跨域:真正的,
beforeSend:功能(XHR){
xhr.overrideMimeType('text / plain的;字符集= UTF-8);
},
成功:函数(XMLHtt prequest,jqXHR,数据){
//alert(data.title);
VAR starttitl = data.lastIndexOf('<冠军>');
VAR endtitl = data.lastIndexOf('< /标题>');
VAR TITLE1 = data.substring(starttitl + 7,endtitl);
警报(TITLE1);
},
错误:函数(ErrorStatus中,XHR){
警报(错误+ JSON.stringify(ErrorStatus中));
}
});
}
< / SCRIPT>
< /头>
<身体GT;
< DIV ID =siteloader>
<输入类型=按钮的onclick =GETIT()/>
< / DIV>
< /身体GT;
< / HTML>
我得到这个错误,在我的情况下,它不是由于同源策略。我从此链接一些帮助
我的情况是,我有一个链接按钮,我并没有使用如preventDefault()
ASPX
< ASP:LinkButton的ID =lnkSearch=服务器的CssClass =DockCmdSearch的CommandName =搜索的OnClientClick =返回VerifySearch(这一点,活动); />
Javascript的
函数VerifySearch(发件人,发送){
即preventDefault();
$阿贾克斯({
键入:POST,
.............
}
返回false;
}
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.
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.
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>
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()
ASPX
<asp:LinkButton ID="lnkSearch" runat="server" CssClass="DockCmdSearch" CommandName="Search" OnClientClick="return VerifySearch(this, event);" />
Javascript
function VerifySearch(sender, e) {
e.preventDefault();
$.ajax({
type: 'POST',
.............
}
return false;
}
这篇关于jQuery的AJAX readystate为0 responseText的状态0状态文本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!