jquery で ajax 呼び出しを介してスクリプトを実行しようとしています。ただし、結果が得られず、クロムのネットワークビューに「(キャンセル)」ステータスが表示されます。これは、.php
スクリプトを要求した場合にのみ発生し.txt
ますが、たとえばファイルのみを要求した場合は正常に機能します。one\ntwo\nthree
以下のファイルでURLを「test.txt」に変更するとアラートが表示されtest.html
ます。私の Web サーバーは正しく構成されており、ファイルのアクセス許可はすべて適切です。ブラウザからスクリプトをリクエストすると、.php
期待どおり「hello」が返されます。以下は私の 3 つのファイルtest.php
ですtest.txt
。
test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" href="/favicon.ico">
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<title>test</title>
</head>
<body>
<button id="b">click</button>
<script>
$("#b").bind("click", function() {
$.ajax({
url: "test.php", // test.txt works fine
type: "GET",
cache: false,
success: function(data) {
alert(data);
}
});
});
</script>
</body>
</html>
test.txt
one
two
three
test.php
<?php
echo "hello";
?>
前述のようにtest.php
、ブラウザでリクエストすると正しい「hello」出力が得られるため、正常に実行されます。
-rwxr-xr-x 1 me me 22 Oct 1 02:49 test.php