Php 非常简单的AJAX调用不起作用
这个非常简单的AJAX调用在我的本地主机上不起作用。我有一台运行XAMPP的Windows10机器。我跟踪了这些包,AJAX请求测试甚至没有发送到handle.php。我做错了什么 ajaxTest.phpPhp 非常简单的AJAX调用不起作用,php,jquery,html,ajax,Php,Jquery,Html,Ajax,这个非常简单的AJAX调用在我的本地主机上不起作用。我有一台运行XAMPP的Windows10机器。我跟踪了这些包,AJAX请求测试甚至没有发送到handle.php。我做错了什么 ajaxTest.php <html> <head> <script src="https://code.jquery.com/jquery-3.2.1.min.js"> $(document).ready(function()
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js">
$(document).ready(function()
{
$.ajax(
{
type: 'post',
url: 'inc/handle.php',
success: function(data)
{
alert("Done!");
}
});
});
</script>
</head>
</html>
<?php
echo "Test!";
?>
$(文档).ready(函数()
{
$.ajax(
{
键入:“post”,
url:'inc/handle.php',
成功:功能(数据)
{
警报(“完成!”);
}
});
});
handle.php
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js">
$(document).ready(function()
{
$.ajax(
{
type: 'post',
url: 'inc/handle.php',
success: function(data)
{
alert("Done!");
}
});
});
</script>
</head>
</html>
<?php
echo "Test!";
?>
问题是:将jquery包含在脚本标记上,并将代码放入另一个脚本标记中
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function()
{
$.ajax(
{
type: 'post',
url: 'inc/handle.php',
success: function(data)
{
alert("Done!");
}
});
});
</script>
</head>
</html>
$(文档).ready(函数()
{
$.ajax(
{
键入:“post”,
url:'inc/handle.php',
成功:功能(数据)
{
警报(“完成!”);
}
});
});
尝试发布`$.ajax({type:'post',url:'inc/handle.php',成功:函数(数据){alert(“Done!”;}}})`仅在浏览器控制台中,如果您得到404,则是路径问题控制台或网络选项卡中有错误吗?请参阅console.log
,或者尝试直接在没有ajax的情况下运行handle.php
。handle.php工作正常。。。正如我所说,我跟踪了包,请求甚至没有发送到handlephp。我检查了控制台,但没有任何错误。@user3877230我很高兴听到这个消息。。祝你今天愉快:-)