1
I’m creating a webmetod that will make the autocomplete of some fields on my screen, however I’m getting error 500
<System.Web.Services.WebMethod>
<System.Web.Script.Services.ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)>
Public Function AutoComplete(ByVal prefixText As String) As String
Dim resposta As string = "funciona"
Return Newtonsoft.Json.JsonConvert.SerializeObject(resposta)
End Function
as you can see it is quite simple just to see if it returns the server message
My javascript
function buscaPorParametro(campo) {
var valorDigitado = $("input[name='" + campo +"']")
console.log(txtBox.val())
$.ajax({
data: JSON.stringify("{ prefixText: '" + valorDigitado.val() + "' }"),
dataType: "json",
url: url,
type: "POST",
contentType: "application/json; charset=utf-8",
success: OnSuccess,
error: onError
});
}
function OnSuccess(data) {
}
function onError(err) {
console.log(err);
$('#LoadingPanel').css('display', 'none');
}
error returned from server
"{"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\u0026 convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\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.Deserialize[T](String input)\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"}"
someone would tell me where I’m going wrong?
Thank you
Bruno talks, man I tried to do this way ... and it didn’t work, he says that because Dictionary is an implementation of the Idictionary interface he can’t convert the object, you managed to run the code like this ???
– Leo
Oops, I forgot the first Dictionary constructor parameter. I edited the answer... give a look
– Bruno Warmling
then I had already noticed that, even doing as it should, the error appears at the moment of climbing the application. The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089]] is not supported because it Implements Idictionary. I think the only way to make it work is by typing an object and putting it in the method signature ... probably this will solve
– Leo
Put string on your webservice and try to send it just like this: valueDigited.val()
– Bruno Warmling
I did otherwise look at the answer, []’s
– Leo