i wanna insert specification of members that enter in textboxs of form in the database .i do this operation with
jquery ajax when i call webmetod with static value the operation do successfully.for example this code is ok.
$.ajax({
type: "POST",
url:"MethodInvokeWithJQuery.aspx/executeinsert",
data: '{ "username": "user1", "name":"john","family":"michael","password":"123456","email": "
[email protected]", "tel": "123456", "codemeli": "123" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
$('#myDiv2').text(msg.d);
},
error: function (x, e) {
alert("The call to the server side failed. " + x.responseText);
}
}
);
but when i wanna use of values that enter in textboxes dynamically error occur.whats problem?i try this two 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>
or
$(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);
}
}
);
}
)
})