0
如何通過使用ajax $ linq插入數據到數據庫? TNX幫助用ajax插入數據庫linq
`function SendData() {
var jName = document.getElementById("txtName").value;
var jFamily = document.getElementById("txtFamily").value;
alert(jName + jFamily);
$.ajax(
{
type: "POST",
url: "m2.aspx/Insert",
data: "{'name':'" + jName + "','family':'" + jFamily + "'}",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function() { alert("Insert Success");},
error: function() { alert("error"); }
});
}
*******************************************************************
[WebMethod(EnableSession = true)]
public static void Insert(string name, string family)
{
DataClasses1DataContext db = new DataClasses1DataContext();
persone p = new persone()
{
Name = name,
Family = family
};
db.persones.InsertOnSubmit(p);
db.SubmitChanges();
}
`
你得到的錯誤是什麼? – Maess
我不知道...問題在這裏....錯誤是什麼? – ssmmoo
你使用asp.net mvc嗎? – BorHunter