我有2個腳本,submit.php
和display.php
。簡單的PHP AJAX腳本
我希望能夠加載submit.php
,點擊提交按鈕&將result
格顯示爲123
。
現在,它只是重新加載我的網頁。我沒有從我的控制檯得到任何東西,所以堅持如何調試。
有人可以看看並提供幫助嗎?
submit.php:
<form>
<input type="submit" value="Submit" name="display" id="display">
</form>
<div id="result"> </div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$("#display").click(function() {
$.ajax({
url: 'display.php',
type: 'GET',
dataType: "html",
data: {
"id": "123",
},
success: function(data) {
//called when successful
$('#result').html(data);
},
error: function(e) {
//called when there is an error
//console.log(e.message);
}
});
});
</script>
Display.php的:
<?php
$id = $_GET['id'];
echo $id;
?>
變化'類型= 「提交」''給類型= 「按鈕」'。您只需提交表單並重新加載頁面。您需要防止提交表單。 – j08691
@ j08691我相信即使那樣,它也會重新加載它。 –
@PraveenKumar如果輸入不是提交按鈕,爲什麼會重新加載? – j08691