[英]jquery $.get() not working on localhost
I'm trying to use jquery $.get() to obtain values from a server file. 我正在尝试使用jquery $ .get()从服务器文件获取值。 Both files are currently on my machine in the /var/www directory (using linux).
这两个文件当前都在我的机器上的/ var / www目录中(使用linux)。
I am aware of the cross-domain restriction for ajax, hence I placed the two files in /var/www. 我知道ajax的跨域限制,因此我将两个文件放在/ var / www中。
The "client" file (f1.htm) is: “客户端”文件(f1.htm)为:
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.9.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
$.get( "f11.htm", function( data, status ){ alert( "1" ); } );
/*
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","f11.htm",false);
xmlhttp.send();
alert( xmlhttp.readyState + " " + xmlhttp.status );
*/
alert( "2" );
</script>
</body>
</html>
while the "server" script (f11.htm) is simply: 而“服务器”脚本(f11.htm)只是:
<html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
</head>
<body>
<?php
echo "server text";
?>
</body>
</html>
the client script ("f1.htm") gets stuck at the $.get() line. 客户端脚本(“ f1.htm”)卡在$ .get()行中。 I've tried this with xmlhttprequest (which is commented), and it works.
我已经尝试了xmlhttprequest(已注释),并且它可以工作。 why is the $.get() line not working?.
为什么$ .get()行不起作用?
TIA TIA
You can try this code to examine the error function being returned instead of the shorthand $.get. 您可以尝试使用此代码检查返回的错误函数,而不是简写$ .get。
$.ajax({
type:'GET',
url: 'f11.htm',
data: {},
success: function(data) {
console.log(data);
}, error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.