jquery を使用して、.php ファイルから情報を取得し、別の HTML ページで実行しようとしています。
これを試すために、次の例を使用しようとしました: http://www.tutorialspoint.com/jquery/ajax-jquery-get.htm
.php ファイルには以下が含まれます。
<?php
if( $_REQUEST["name"] )
{
$name = $_REQUEST['name'];
echo "Welcome ". $name;
}
?>
================ HTMLページコードには以下が含まれます:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Sandbox</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
// has the google object loaded?
if (window.google && window.google.load) {
google.load("jquery", "1.3.2");
} else {
document.write('<script type="text/javascript" src="http://joecrawford.com/jquery-1.3.2.min.js"><\/script>');
}
window.onload = function() {
$('#test').css({'border':'2px solid #f00'});
};
</script>
</head>
<body>
<!-- -------- Test jQuery -------- -->
<p id="test">hello jQuery</p>
<!-- -------- /end Test jQuery -------- -->
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#driver").click(function(event){
$.get(
"/testing.php",
{ name: "Zara" },
function(data) {
$('#stage').html(data);
}
);
});
});
</script>
<p>Click on the button to load result.html file:</p>
<div id="stage" >
STAGE
</div>
<input type="button" id="driver" value="Load Data" />
</body>
「テスト結果」によると、jquery ライブラリは正常にロードされました。
何らかの理由で、「testing.php」ファイルの内容がプルされていません...まるで間違ってリンクされているかのようです。ファイルのリンクが間違っていませんか? (.php ファイルと .html ファイルの両方が同じフォルダーにあります)
PHP の echo ステートメントのような単純なことを試してみましたが、ファイルから何も取得されず、html ページに公開されませんでした。
あなたが見る簡単な修正があるかもしれません。この問題の解決にご協力いただき、ありがとうございます。前もって感謝します!