我正在学习 JQuery Get 方法。我启动了一个 Python HTTP 服务器:
(只需输入命令“ Python -m SimpleHTTPServer ”)。
只需在我的网络浏览器上访问“http://localhost:80”即可测试此网络服务器。但是,当我编写这个非常简单的 javascript 来访问我的网络服务器时。我收到一条错误消息:
“代码 501,消息不受支持的方法('OPTIONS')”
我使用假设跨域请求 JQuery 的 jquery.xdomainajax.js 库。
这是我的javascript代码:
<html>
<head>
<script src="jquery.min.js"></script>
<script src="jquery.xdomainajax.js"></script>
<script type="text/javascript">
$(document).ready(function(){
u = 'http://localhost:80';
jQuery.get(u, function(res){
$("#data").html(res.responseText)
});
});
</script>
</head>
<body>
<p id="data"></p>
</body>
</html>
实际上,如果我将您更改为任何其他网址,例如“http://www.google.ca”。它工作得很好。但我不知道为什么它不适用于基本的 Python HTTP 服务器。谁能帮我?