Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax成功,但只是以文本形式返回服务器PHP代码_Php_Jquery_Ajax - Fatal编程技术网

Ajax成功,但只是以文本形式返回服务器PHP代码

Ajax成功,但只是以文本形式返回服务器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

我正在运行一个非常简单的Jquery.Ajax调用作为测试。代码应该可以工作,因为它是来自编程类的示例。然而,在我的Windows XAMPP上,我在警报中得到的只是html格式的ajax.php代码。。。不过,我确实从Ajax查询中获得了一个成功的200代码。我不知道怎么回事。有人有什么建议吗

Ajax.html

<!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