Hello, I can't seem to convince my web service to return json data. It always returns the data in xml. There seem to be hundreds of threads with people who have a similar problem but none of the solutions I've found so far have worked for me. Thanks in advance to anyone who has a look.
I'm just starting out so the service is very basic at this point:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization<WebService(Namespace:="http://example.com/webservices/")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<ScriptService()> _
Public Class WebService
Inherits System.Web.Services.WebService<WebMethod()> _<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XmlSerializeString:=False)> _
Public Function getLogins() As String
Dim js As JavaScriptSerializer = New JavaScriptSerializer()
Return js.Serialize("@")
End Function
End ClassI'm not sure if the data needs to be preserialized but I've tried it with a simple return "@" as well to no effect.
Here is my client test code:
<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><script type="text/javascript"></script><link rel="stylesheet" href="../aistyle.css" type="text/css" /><style type="text/css"></style><script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script><script type="text/javascript">
window.onload = function() {
$.ajax({
type: "POST",
url: "WebService.asmx/getLogins",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("!");
}, //success
error: function(msg, error, errorThrown) {
alert(error + ":\r\n" + msg.responseText +":\r\n"+ errorThrown);
}//error
});
}//end onload
</script></head><body></body></html>