Please am doing a AJAX call to a web API as below
$.ajax({
type: "POST",
url: "CustomerService.asmx/GetAccounts",
data: '{"custid":"' + cusID + '"}',
contentType: "application/json; charset-utf-8",
dataType: "json",
success: function (data) {
datatableVariable = $('#dtAccounts').DataTable({.......
This is my ASP.NET Web Method
<WebMethod()>
Public Sub GetAccounts(ByVal custid As Integer)
Dim sql As String = "Select * from Accounts WHERE CustomerID =" & custid & " Order by ID"
Dim constr As String = ConfigurationManager.ConnectionStrings("flashCon").ConnectionString
Dim accs = New List(Of Accounts)()
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(sql)
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
Dim dr = cmd.ExecuteReader()
If dr.HasRows Then
While dr.Read
Dim acc = New Accounts() With {
.custID = Convert.ToInt32(dr("CustomerID").ToString()),
.AccNum = dr("AccountNumber").ToString(),
.Descri = dr("Description").ToString(),
.CurrBalance = dr("CurrentBalance").ToString(),
.typOA = dr("TypeOfAccount").ToString(),
.Frozen = dr("Frozen").ToString()
}
accs.Add(acc)
End While
End If
End Using
End Using
Dim js = New JavaScriptSerializer()
Dim strResponse As String = js.Serialize(accs)
Context.Response.Write(strResponse)
End Sub
The JSON string response returned is the below with additional strange {"d":null} value that I dont know where its coming from
[{"custID":2,"AccNum":"KODSW00002","Descri":"","CurrBalance":0,"Frozen":false,"typOA":0}]{"d":null}
If I use Context.Response.Flush() it disappears but then I get another error from the browser Server cannot clear headers after HTTP headers have been sent.
Please can someone assist me to resolve this,been doing this for weeks now
Thanks a lot