1
私は以下のコードを持っています。現在のところ、first_nameだけを送信します。これは、私が望むものであり、ページをリフレッシュせずにその場で実行します。キーアップ時の投稿ID AJAX/PHP/MYSQL
しかし、私は隠されたIDフィールドを通じて同じAjaxリクエストに沿ってID番号を解析する必要があります。
誰でも私を助けるアイデアを提案できますか?
事前に感謝
CODE:
<html>
<head>
<script>
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "my_parse_file.php";
var fn = document.getElementById("first_name").value;
var vars = "firstname="+fn+;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
</script>
</head>
<body>
<h2>Ajax Post to PHP and Get Return Data</h2>
<input type="hidden" name="my_id" value="1234">
First Name: <input id="first_name" name="first_name" type="text" onkeyup="ajax_post();"> <br><br>
<div id="status"></div>
</body>
</html>
varが= "FIRSTNAME =" + FN + '&my_id =' +ドキュメントをvarsの。 getElementById( "my_id")。value; – Surace