I'm creating a login user control for our sitefinity. it is designed to use jQuery/Webservice. I've built the client side with the following:
The above works ok, the service is called(as expected). However I don't know how to get the json data out of the POST message(data : info). With Get, I can read the parameters off the url query string. I can parse the json ok, I just don't know how to get it from the POST. I have the following code for the webservice.
I hope I got this in the right forum section.
<input type="text" id="UserNameText" /> <br /> <input type="password" id="PasswordText" /> <br /> <input type="button" id="Login" value="Login" onclick="DoLogin();" /> <script type="text/javascript" language="javascript"> function DoLogin() { var un = document.getElementById('UserNameText').value; var pw = document.getElementById('PasswordText').value; var info = "{ 'UserName':'" + un + "', 'Password':'" + pw + "'}"; $.ajax( { type: "POST", url: "http://localhost:60876/Sitefinity/Services/Login/Login.asmx/LoginSpecial", dataType: 'json', data: info, contentType: "application/json; charset=utf-8", success: function (msg) { alert(msg.d); }, error: function (msg) { alert(msg.responseText); } }); } </script>The above works ok, the service is called(as expected). However I don't know how to get the json data out of the POST message(data : info). With Get, I can read the parameters off the url query string. I can parse the json ok, I just don't know how to get it from the POST. I have the following code for the webservice.
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] [WebMethod] public string LoginSpecial() { string success = String.Empty; /* read json here from jQuery POST NameValueCollection collection = request.Params;
HttpRequest request = HttpContext.Current.Request;
string json = HttpContext.Current.Request["info"] != null ? HttpContext.Current.Request["info"].ToString() : String.Empty; */ // test json string, need to read from the jquery post string json = "{ 'UserName':'test', 'Password':'test'}"; // the following two lines of code work ok with the test json string above. JavaScriptSerializer serial = new JavaScriptSerializer(); Credentials credential = (Credentials)serial.Deserialize(json, typeof(Credentials)); return "Some json message here"; }I hope I got this in the right forum section.