本文介绍了单击按钮时使用ajax更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在javascript中有一个ajax函数,它是在按钮点击时更新数据库;下面是ajax片段。这段代码有什么问题?
我的意思是数据库没有更新!!
I have an ajax function in a javascript which is to update database on button click; below is the ajax snippet. What is the mistake in this code?
I mean the database is not getting updated!!
<script type="text/javascript">
function sav() {
var class_id5 = document.getElementById('ddlClass5');
var class_id6 = document.getElementById('ddlClass6');
var class_id7 = document.getElementById('ddlClass7');
var subj_id = document.getElementById('ddlSubject');
var mark5 = document.getElementById('txtMark5');
var mark6 = document.getElementById('txtMark6');
var mark7 = document.getElementById('txtMark7');
$.ajax({
type: "POST",
url: "Student.aspx/SaveData",
data: {"class_id5": class_id5, "subj_id": subj_id, "mark5": mark5, "class_id6": class_id6, "class_id7": class_id7,
"mark6":mark6,"mark7":mark7},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: alert("success")});
}
</script>
推荐答案
<script type="text/javascript">
function sav() {
var class_id5 = document.getElementById('ddlClass5').value;
var class_id6 = document.getElementById('ddlClass6').value;
var class_id7 = document.getElementById('ddlClass7').value;
var subj_id = document.getElementById('ddlSubject').value;
var mark5 = document.getElementById('txtMark5').value;
var mark6 = document.getElementById('txtMark6').value;
var mark7 = document.getElementById('txtMark7').value;
这篇关于单击按钮时使用ajax更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!