使用jquery,我試圖從.php文件中提取信息並在另一個html頁面中運行它。如何使用jquery從.php文件中拉出一些php並在另一個頁面上運行它?
要嘗試使用此我試圖用這個例子: 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頁面。
您可能會看到一個簡單的修復程序。我很感激你幫助我解決這個問題的時間和精力。提前致謝!
嘗試改變'「/測試。 PHP「'到'」testing.php「' –
,但等待這已經起作用了。我只是在我的服務器上試過你的代碼,它的工作方式和你的期望一樣所以你面臨的問題是什麼? –
jQuery 1.3.2?這差不多已經三年了。使用庫的最新版本。 – Quentin