I'm trying to write username validation using jquery, I'm using jmsajax plugin.I have tested webservice, it work fine.
I'm getting error.
Webservice code
[System.Web.Script.Services.ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public bool check_username(string uname)
{
DBMOdelDataContext db = new DBMOdelDataContext();
var q = from p in db.users
where p.username == uname
select p;
if (q.Count() == 0)
return false;
else
return true;
}
Jquery code.
$(document).ready(function() {
$(".unamebtn").blur(function() {
$uname = $(this).val();
$.jmsajax({
type: "POST",
url: "Services/MyServices.asmx",
data:"{userName='" + $uname + "'}",
method: "check_username",
dataType: "msjson",
success: function(result) {
$("#msg").html(result);
alert(result);
$("#msg").addClass("notice");
}
});
});
});
The Exception it is throwing.
{"Message":"Cannot convert object of type \u0027System.String\u0027 to type \u0027System.Collections
.Generic.IDictionary`2[System.String,System.Object]\u0027","StackTrace":" at System.Web.Script.Serialization
.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean
throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain
(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject
)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer
serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer
serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer
.DeserializeT\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest
(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler
.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services
.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType"
:"System.InvalidOperationException"}