好吧,我是新來的Ajax。我的問題是我不確定如何檢索<input>
標記中的數據並將其發送到Ajax。我試圖在互聯網上搜索,但大多數解決方案都使用jQuery Ajax,這是我目前沒有在尋找的。如何將輸入值傳遞給ajax
這是我的代碼。
我要保存這個值,這樣我的Ajax可以讀取它...
<input id="IDValue" name="IDValue" value="<?php echo $row['exist']?>" >
這是我的Ajax腳本...
function message(){
var ID=$(".IDValue").val();
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("POST","retrieveMsg.php?q=" +ID,true);
xmlhttp.send();
}
請幫幫我,夥計們。我做這個方法的原因是(我以前的帖子)Send input value to php using ajax with result printed to div
好吧,不過你要使用jQuery來獲得輸入字段值。你正在把它放在面前,但你需要一個散列。 (var ID = $(「#IDValue」)。val();) – KiwiJuicer
'var ID = document.querySelector('#IDValue')。value;'是非jquery的等價物。 – Shilly
查看https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Submitting_forms_and_uploading_files。 –