2017-03-02 7 views
1

私は非常に単純なJquery.Ajax呼び出しをテストとして実行しています。コードは、プログラミングクラスの例のように動作するはずです。しかし、私のWindows XAMPPでは、アラートに戻ってくるのは、html形式のajax.phpコードです... Ajaxクエリーから200のコードを取得します。私は何が間違っているのか分からない。誰にも何か提案はありますか?JQuery.Ajax成功ですが、サーバPHPコードをテキストとして返します。

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

http://php.net/manual/en/language.basic-syntax.phptags.phpはあなたがちょうど来Ajax.phpファイルの内容全体を参照してください意味ですか警報の中で?あなたのPHPファイルにHTMLがない場合、 "HTML形式"について何を意味するのかは不明です。 ajax.php変更の変更の – nnnnnn

+1

<? 〜<?php –

+0

'<?'はショートタグと呼ばれます。これらの短いタグの解釈は、 'php.ini'ファイルでは無効にすることができます。したがって、PHPの開始タグには '<?php'形式を使用する方が常に安全です。それらがオフになっている場合、スクリプトはPHPコードとして解釈されるのではなく、通常のテキストと同様に解釈され、呼び出し元にそのように返されます – RiggsFolly

答えて

1

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 
関連する問題