それは「空」をエコーします..助けてください、私は問題を見つけることができません! どちらも AJAX によって呼び出されます。最初のコードは、新しい TR をテーブルに作成します。addnewTape() 関数を使用して、他の php にデータを送信したいと思います。しかし、POST 配列は空です。
テーブルへの新しい TR (newtapeTR.php):
echo "<form id='tapeform".$_SESSION['newtape']."' method='POST' action=''>";
echo "<td> <input type='text' value='".$_SESSION['newtape']."' name='tapeid' readonly style='width: 25px;'></td>";
echo "<td> <input type='text' placeholder='citation' name='tapetext' style='width: 625px;'> </td>";
echo "<td id='tapeadd".$_SESSION['newtape']."' colspan='2'> <input type='button' onClick='addnewTape(".$_SESSION['newtape'].");' value='Add' class='button' ></td>";
echo "</form>";
フォーム送信、AJAX 関数 (例:) addnewTape(32) newtape.php:
if (empty($_POST))
{
echo "empty";
}
else
{
$tapeid = $_POST['tapeid']; //this should be 32
$tapetext = $_POST['tapetext']; //this should be some text
}
アヤックス:
function addtapeTR(){
var xmlhttp;
var tapetableRef = document.getElementById('tapetitle');
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var newRow = tapetableRef.insertRow(-1);
var lastRowIndex = tapetableRef.rows.length-1;
var newID = lastRowIndex-1;
newID++;
newRow.id = "tape"+newID;
newRow.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","menu-main/menu-setting-submenu/newtapeTR.php",true);
xmlhttp.send();
}
この ajax は newtape.php を呼び出し、id とテキストを送信します。
function addnewTape(id) {
var id = id-1;
if (tapeid[id].value=="" || tapetext[id].value=="") {
alert('Empty field!');
} else {
$.ajax({
type: "POST",
url: "menu-main/menu-setting-submenu/newtape.php",
data: $("#tapeform"+(id+1)).serialize(),
success: function(data){
$("#tape"+(id+1)).html(data);
}
});
}
}
回答: 次のデータに問題が発生しました:
data: $("#tapeform"+(id+1)).serialize(),
jQuery と GET を使用せずに実行しました。今では動作します。ヒント、この行で何がうまくいかなかったのですか?