我正在运行一个非常简单的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>
Ajax.php
<?
if ($_POST["i_want_text"]) {
print "text received with value of " . $_POST["i_want_text"];
}
?>
答案 0 :(得分:1)
来自php文档http://php.net/manual/en/language.basic-syntax.phptags.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