1
- 你好我在AJAX初學者,在下面的代碼不彈出警告消息面臨的一個問題。
- 我嘗試使用AJAX來從表單數據插入到數據庫中。
- 此代碼成功地將數據存儲到數據庫中。
- 但它不會彈出警告消息是主要問題。
**//index.php**
// following is ajax code in which problem occur. i think.
$(document).ready(function(){
$('#submit').click(function(){
$.ajax({
url:"store.php",
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
}
});
});
});
**//store.php**
// following is the data base releted query
$conn = mysqli_connect("localhost", "root", "", "prag");
$chapter_name = $_POST["chapter_name"];
$class = $_POST["class"];
$subjects = $_POST["subjects"];
$sql = "INSERT INTO chapter(class_id,subject_id,name) VALUES('$class','$subjects','$chapter_name')";
mysqli_query($conn, $sql);
\t \t \t \t echo "Data Inserted";
</pre>
//HTML CODE
//Following are the input fields through which data will store.
<input type="text" name="chapter_name" placeholder="Enter the Chapter name" class="form-control name_list" />
<select name="class" id="class" class="form-control">
<option>Select Class</option>
</select>
<select name="subjects" id="subjects" class="form-control"> \t \t \t
</select>
\t \t \t \t \t \t \t \t \t \t
<button type="submit" name="add_chapter" id="submit">Add </button>
<pre>
錯誤部分用同樣的警告,所以你加入Ajax調用可以檢查ajax調用是否真的成功 – RST
該代碼示例是否爲HTML完整?你的表單標籤在哪裏?點擊提交時你觀察到什麼? – bcmcfc
,即時通訊面臨的問題是唯一的,這不彈出操作成功後的提示框 –