我有下面的代碼,並試圖通過使用JQuery和Ajax的GET HTTP請求傳遞數據。當在文本框中輸入「Example」並點擊「Go」時,我希望「example」回到反饋div中。沒有任何東西被返回。我將不勝感激爲什麼這不起作用的任何幫助。謝謝。使用JQuery和Ajax獲取HTTP請求
文件名是 「trial.php」
<body>
<script type="text/javascript" src="jquerycode.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<input id = "string" type = "text" />
<input id = "button" type = "button" value = "Go" />
<div id = "feedback"></div>
</body>
文件名是 「ajax.js」
$('#button').click(function()
{
var string = $('#string').val();
$.get('file.php', { input: string }, function(data) {
$('#feedback').text(data);
});
});
文件名是 「file.php」
<?php
if(isset($_GET['input']))
{
$string = $_GET['input'];
echo strtolower($string);
}
?>
也許,你可以打印在PHP端的數據,看看到底是怎麼回事。並且請避免調用您的變量字符串,這可能會導致很多瘋狂的錯誤。 – lc2817
你使用螢火蟲檢查過它嗎?結果是什麼? –
如果你執行'print_r($ string)',你會得到什麼,並檢查你通過'console.log(data)'或'alert(data)'獲得GET請求的成功回調的內容; – Rafay