I have reviewed some previous posts, but unfortunately, they did not provide the help I need. When my program runs and I click on a button to trigger a JavaScript function, nothing happens - there is no response. In the Chrome debugger under the network tab, I see a URL highlighted in red:
http://wms-wsdl.company.net/mobile.asmx/ContactGet?searchField=test&office=97&person=119&user=531&organization=14
Clicking on this link results in a red circle with a 500 internal server error. Examining the response, I see:
{"Message":"Invalid JSON primitive: test.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, 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.Services.RestHandler.GetRawParamsFromGetRequest(HttpContext context, JavaScriptSerializer serializer, WebServiceMethodData methodData)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
I am unable to decipher the meaning of this response.
When I double-click on the link, it displays all the data that should be inserted into a list view (the data is XML) such as
<string xmlns="http://company.net/">[{ "Name": "Myar", "Surname": "Tester", "Mobile": "080000000", "Email": "" ......}, etc
The JavaScript function I'm using is as follows:
function initContactView()
{
alert("ContactView start test")
var txtSearch = $("#searchTextField").val();
$.ajax({
type: "GET",
dataType:"json",
contentType: "application/json; charset=utf-8",
crossDomain: true,
url: "http://dsf-wsdl.company.net/mobile.asmx/ContactGet",
data: "searchField="+txtSearch+"&office="+localStorage.getItem("office")+"&person="+localStorage.getItem("person")+"&user="+localStorage.getItem("user")+"&organization="+localStorage.getItem("organization"),
success:successContact,
failure: function (msg) {
console.log(msg);
alert(msg)
}
});
alert("ContactView End Test");
}
function successContact(data) {
alert("Success Start Test");
window.location = "#contactsview";
$("#lstView_contacts").kendoMobileListView({
dataSource: JSON.parse(data.d),
template: $("#lstView_contact_Template").html(),
endlessScroll: true,
scrollThreshold: 8
});
alert("Success Start Test");
}
searchTextField
is retrieved from my HTML textbox.
It seems strange that despite getting the expected data, an error still occurs. The web service I am utilizing is a JSON webservice. Both alerts are triggered, but I suspect it goes into the failure state.
The response I receive in the debugger is:
<string xmlns="http://company.net/">[
{
"Name": "Myar",
"Surname": "Tester",
"Mobile": "080000000",
"Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c48594f487c48594f48125f5351">[email protected]</a>"
}]</string
This is how my web service looks:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function ContactGet(ByVal searchField As String, ByVal office As String, ByVal person As String, ByVal user As String, ByVal organization As String) As String
Dim objSearch As New ArrayList
Dim objSearching As New Search
Dim intResult As Integer
Try
'Test String
intResult = objSearching.SearchByKeyword(searchField, person, office, organization, user, company.ETMyProperty.Search.enmSearchType.enmContact, objSearch)
Dim objContact As New Person
Dim dt As New DataTable("Contacts")
Dim col_Name As New DataColumn("Name", GetType(String))
dt.Columns.Add(col_Name)
Dim col_Mobile As New DataColumn("Surname", GetType(String))
dt.Columns.Add(col_Mobile)
Dim col_Office As New DataColumn("Mobile", GetType(String))
dt.Columns.Add(col_Office)
Dim col_Category As New DataColumn("Email", GetType(String))
dt.Columns.Add(col_Category)
Dim dr As DataRow
For i = 0 To objSearch.Count - 1
dr = dt.NewRow()
dr("Name") = DirectCast(objSearch(i), company.ETMyProperty.Search).Return2
dr("Surname") = DirectCast(objSearch(i), company.ETMyProperty.Search).Return3
dr("Mobile") = DirectCast(objSearch(i), company.ETMyProperty.Search).Return6
dr("Email") = DirectCast(objSearch(i), company.ETMyProperty.Search).Return7
dt.Rows.Add(dr)
Next
Dim serializer As New JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object) = Nothing
'serialize dt row to json output
For Each drow As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
Next
rows.Add(row)
Next
Dim str_json = JsonConvert.SerializeObject(dt, Formatting.Indented)
Return str_json
Catch ex As Exception
Return Nothing
End Try
End Function
I've been tackling this issue for a few days now without finding a solution. Any advice would be greatly appreciated.