在javascript函数上将记录插入数据库但ajax失败并给出error.first我试图一键插入三个记录,但它不起作用,因此我在按钮click上调用javascript函数,通过获取ID逐个插入记录和价值。javascript功能:<script type="text/javascript"> debugger; $(document).ready(function () { $('#btnEmail1').click(function () { var email1 = $("#email1").val(); var chk = $("#chk1").val(); $.ajax({ type: "POST", url: "/User/AddTeamEmail", data: JSON.stringify(email1 + chk), contentType: "application/json; charset=utf-8", dataType: "json", success: function (r) { alert(r + " record(s) inserted."); } }); }); $("#btnEmail2").click(function () { debugger; var email = $("#email2").val(); //var chk2 = $("#chk2").val(); alert(email); $.ajax({ type: "POST", url: '/User/AddTeamEmail', data: "{'email': '" + email + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (r) { alert("success"); alert(r + " record(s) inserted."); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("Status: " + textStatus); alert("Error: " + errorThrown); alert("error") } }); }) $("#btnEmail3").click(function () { debugger; var email3 = $("#email3").val(); var chk3 = $("#chk3").val(); $.ajax({ url: "/User/AddTeamEmail", data: JSON.stringify(email3 + chk3), contentType: "application/json; charset=utf-8", dataType: "json", success: function (r) { alert(r + " record(s) inserted."); } }); }) });</script>
添加回答
举报
0/150
提交
取消