htm和php文件不在同一个域名下,htm文件在免费虚拟主机上,php文件在localhost上,运行htm文件上的ajax为什么没有生成test.txt文件?测试网页如下
http://linjuming.megabyet.net/index.htm代码:<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
function send_local(){
var my_html=$("#test").html();
$.ajax({
type:"POST",
url:"http://localhost/mycenter/test.php",
data:{my_html:my_html},
success:function(){alert("send ok")}
});
}
</script>
</head>
<body>
<div id="test">test data</div>
<div>
<button onclick="send_local();">传到本地php</button>
</div>
</body>
</html>test.php 代码如下:<?php
$my_html=$_POST['my_html'];
file_put_contents("test.txt",$my_html);
?>