Ajax成功,但只是以文本形式返回服务器PHP代码
我正在运行一个非常简单的Jquery.Ajax调用作为测试。代码应该可以工作,因为它是来自编程类的示例。然而,在我的Windows XAMPP上,我在警报中得到的只是html格式的ajax.php代码。。。不过,我确实从Ajax查询中获得了一个成功的200代码。我不知道怎么回事。有人有什么建议吗 Ajax.htmlAjax成功,但只是以文本形式返回服务器PHP代码,php,jquery,ajax,Php,Jquery,Ajax,我正在运行一个非常简单的Jquery.Ajax调用作为测试。代码应该可以工作,因为它是来自编程类的示例。然而,在我的Windows XAMPP上,我在警报中得到的只是html格式的ajax.php代码。。。不过,我确实从Ajax查询中获得了一个成功的200代码。我不知道怎么回事。有人有什么建议吗 Ajax.html <!DOCTYPE html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1
<!DOCTYPE html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// Handler for .ready() called.
useJQuery();
});
function useJQuery() {
$.ajax({
type: 'POST',
url: "ajax.php",
data: { i_want_text:'yes' },
success: function (response) { alert(response); },
});
}
</script>
</head>
<body>
</body>
</html>
$(文档).ready(函数(){
//调用了.ready()的处理程序。
useJQuery();
});
函数useJQuery(){
$.ajax({
键入:“POST”,
url:“ajax.php”,
数据:{i_want_text:'yes'},
成功:函数(响应){警报(响应);},
});
}
Ajax.php
<?
if ($_POST["i_want_text"]) {
print "text received with value of " . $_POST["i_want_text"];
}
?>
来自php文档
PHP允许短的open标记您的意思是您只看到警报中出现的Ajax.PHP文件的全部内容吗?当PHP文件中没有HTML时,不确定“HTML格式”是什么意思。在ajax.PHP中更改打开
PHP allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).`
so In ajax.php change <? to <?php