所以我試圖傳遞一些JSON對象的信息,並有一個PHP頁面插入數據到數據庫。但是,我遇到了一些麻煩。 「更新」按鈕存在於一個彈出窗口中。然後用戶點擊「更新」,輸入的數據應該被相應地處理。但是,我擔心我甚至沒有達到我的.click功能。我的警報似乎沒有被觸發。下面我會指出問題的發生地點。謝謝!通過AJAX傳遞JSON加按鈕Dilema
<script>
function updateTable()
{
document.getElementById("testLand").innerHTML = "Post Json";
//echo new table values for ID = x
}
$('#update').click(function() {
alert("help!");
var popupObj = {};
popupObj["Verified_By"] = $('#popupVBy').val();
popupObj["Date_Verified"] = $('#popupDV').val();
popupObj["Comments"] = $('#popupC').val();
popupObj["Notes"] = $('#popupN').val();
var popupString = JSON.stringify(popupObj);
alert(popupString);
#.ajax({
type: "POST",
dataType: "json",
url: "popupAjax.php",
//data: 'popUpString = '+ popupString,
data: popupObj,
cache: false,
success: function(data) {
updateTable();
alert("testing tests");
}
});
});
</script>
<html>
<button onClick="openPopup(<?php echo $row['ID'];?>);"><?php echo $row['ID'];?></button> <!--opens a popup with input options-->
<button id="update">Update</button> <!-- this button is supposed to cause the javascript above to run when clicked, however none of my alerts seem to be reached.-->
</html>
謝謝你看!
看到代碼在這裏工作:http://jsbin.com/zocekohalo/1/edit?html,js,output – 2014-10-30 22:48:08