0
沒有數據
我似乎不具有當窗體通過jQuery的AJAX提交POST
我的問題的一個片段(代碼減少到簡化)提交發送的任何數據:
頭:
<script>
function dSubmit(formName, formAction, fieldsToCheck, divToHide){
// No Errors process form
var url = formAction; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#" + formName).serialize(), // serializes the form's elements.
success: function(data)
{alert(data)}
});
return false; // avoid to execute the actual submit of the form.
}
</script>
體:
<a onclick="dSubmit('treatmentDetails','treatments/processTreatments.php','','')"><img style="width:35px;" src="i/update-icon.png"/></a>
<form name="treatmentdetails" id="treatmentdetails"
action="processTreatments.php" method="POST">
<input type="text" name="treatmentName" value="<?php echo $treatment;?>"/>
<input type="text" name="treatmentId" value="<?php echo $treatmentId;?>"/><br>
</form>
PHP(治療/ processTreatments.php):
$table = $dbPrefix."treatmentsOptions";
$treatmentId = $_POST['treatmentId'];
$treatmentName = $_POST['treatmentName'];
$query = mysql_query("UPDATE $table SET name='$treatmentName' WHERE id='$treatmentId'");
echo "variables = id: $treatmentId name: $treatmentName"; // according to jquery submit neither variable appear
PHP收到一個Ajax請求?另外,在Ajax處理過程中是否有錯誤? – mokamoto12
你看過控制檯的錯誤嗎?您是否嘗試過在通過AJAX提交之前將表單數據打印到控制檯? – Difster
如果我添加一個標準的提交按鈕並避免使用ajax,那麼數據庫會在ajax提交時更新,警報讀取'variables = id:name:'並且沒有數據並且沒有數據庫更新發生。我不確定序列化部分是否正常工作,或者是否需要循環輸入(它們會根據表單而不同)。感謝您的輸入。 – pbytes