i have a form with c#(.net4) code behind . in this form user fill his specification and submit.
i wanna use ajax or post method in jquery for prevention of blink.i write flowing code. "success" function execute but it does not work and any record insert in database;i execute executemember method separately.it works without problem but it does not work with jquery ajax.where is problem?
[WebMethod]
public static string executeinsert(string name ,string family , string username,string password , string email,string tel, string codemeli)
{ string constring = "data source=.;database=site;integrated security=true;";
SqlConnection con = new SqlConnection(constring);
SqlCommand com = new SqlCommand("insertmember", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 250));
com.Parameters["@username"].Value = username;
com.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 150));
com.Parameters["@name"].Value = name;
com.Parameters.Add(new SqlParameter("@password", SqlDbType.NVarChar, 50));
com.Parameters["@password"].Value = password;
com.Parameters.Add(new SqlParameter("@family", SqlDbType.NVarChar, 250));
com.Parameters["@family"].Value = family;
com.Parameters.Add(new SqlParameter("@email", SqlDbType.NVarChar, 50));
com.Parameters["@email"].Value = email;
com.Parameters.Add(new SqlParameter("@codemeli", SqlDbType.NChar, 10));
com.Parameters["@codemeli"].Value = codemeli;
com.Parameters.Add(new SqlParameter("@tel", SqlDbType.NChar, 12));
com.Parameters["@tel"].Value = tel;
con.Open();
com.ExecuteNonQuery();
con.Close();
return "success";
}
and its my jquery code
<script type="text/javascript">
$(document).ready(
function () {
$("#Button1").click(
function () {
var username, family, name, email, tel, codemeli, password;
username = $('#<%=TextBox1.ClientID%>').val();
name = $('#<%=TextBox2.ClientID%>').val();
family = $('#<%=TextBox3.ClientID%>').val();
password = $('#<%=TextBox4.ClientID%>').val();
email = $('#<%=TextBox5.ClientID%>').val();
tel = $('#<%=TextBox6.ClientID%>').val();
codemeli = $('#<%=TextBox7.ClientID%>').val();
$.ajax(
{
type: "POST",
url: "WebApplication20.aspx/executeinsert",
data: "{'username':'username','name':name,
'family':family,'password':password,
'email':email,'tel':tel,
'codemeli':codemeli}",
contentType: "application/json;charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function(msg) {
alert(msg);
},
error: function (x, e) {
alert("The call to the server side failed. "
+ x.responseText);
}
}
);
}
)
})
</script>
thank