我在使用这个代码:url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm)
时,遇到了以下错误:jquery ajax readystate 0 responsetext status 0 statustext error
。但是当我在本地主机上使用 url(localhost:""/embparse_page)
时,它却能够正常工作。
我已经尝试使用在谷歌搜索中找到的头文件,并使用了beforeSend:""
,但仍然无法正常工作。
我认为主要问题是:"XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin "local server" is not allowed by Access-Control-Allow-Origin.
",但我不明白这是什么意思。
请问有人能向我解释一下这个问题吗?因为我还比较新手。
<!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>
alert
,因为这是最烦人的调试方式。尝试使用console.log
,并在Chrome中按下F12或在Firefox中按下Ctrl + Shift + K打开控制台。您可以在那里使用许多工具,例如设置断点和检查带有请求和响应标头的请求。 - HMR