c# - Ajax jquery passing multiple parameters web services -
<script type="text/javascript"> $('#btnregister').click(function () { $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: "fetchusers.asmx/regusers", data: "{ username: '" + $("#txtuser").val() + "name: '" + $("#txtname").val() + "'}", datatype: "json", success: function (data) { alert("successfully register"); $("#btnregclose").click(); } }); }); </script> <div id="registration"> <fieldset> <legend>registration form</legend> <input id="txtuser" type="text" placeholder="username" /><br /> <input id="txtname" type="text" placeholder="name" /><br /> <input id="txtpass" type="password" placeholder="password" /><br /> <input id="txtconfirmpass" type="password" placeholder="confirm password" /><br /> <input id="btnregister" type="button" value="register" /> <input id="btnregclose" type="button" value="close" /> </fieldset> </div> [webmethod] public string regusers(string username, string name) { string response = username + name; return response; }
i'm beginner in ajax jquery , i'm doing exercise improve knowledge it. problem when click #btnregister it's not working. think there's problem in parameters passed on ajax don't know it.
try :
$(document).ready(function () { $('#btnregister').click(function () { var obj = { username: $("#txtuser").val(), name: $("#txtname").val() }; $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: "fetchusers.asmx/regusers", data: json.stringify(obj), datatype: "json", success: function (data) { alert("successfully register"); $("#btnregclose").click(); } }); }); });
this worked in local enviroment.
Comments
Post a Comment