我正在使用jquery发出一个GET请求,但没有得到响应可能有什么问题? 下面是html代码。我正在收到警报
请有人向我提供一些运行示例,其中应使用一些知名网站,我也可以访问http://www.google.co.in或http://www.jlcindia.com
错误:错误
<html>
<script type="text/javascript" src="jquery-1.8.1.min.js"></script>
<Script Language="JavaScript">
function getFullName(){
//alert('fun call');
$.ajax({
type: "GET",
url: "http://www.jlcindia.com",
dataType: "html",
success: function(data) {
alert('success'+data);
},
error: function(xhr, textStatus, errorThrown) {
if (textStatus !== null) {
alert("error: " + textStatus);
} else if (errorThrown !== null) {
alert("exception: " + errorThrown.message);
}
else {
alert ("Don't know what is error");
}
}
});
}
</Script>
<body>
<input type="button" value="Show Full Name" onClick="getFullName()">
</body>
</html>
答案 0 :(得分:2)
您正在向其他域发出ajax请求。由于same origin policy
,这不会奏效实施例: 您的网站托管在www.mydomain.com上,您正试图通过ajax访问www.otherdomain.com。这是不可能的。
Ajax请求仅在与托管脚本相同的域上工作。