Am I missing something? I am trying to create a web service and consumer in asp.net, using JSON with JQuery, but I'm not having any luck. I can get JQuery to call the service, and get the service to reply, but the response always goes through the "error" callback in JQuery. When I view the response in FireBug, it appears to be XML, not JSON. Below is my service and the relevant JQuery from the client. Any help would be appreciated:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class ajaxService : System.Web.Services.WebService {
[WebMethod()]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
return "Hello World";
}
}
***********************
JQuery
***********************
$(document).ready(function()
{
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
url : "ajaxService.asmx/HelloWorld",
success : function( msg ) { alert( "success " + msg.d ); },
error : function( err ) { alert( err.status + " : " + err.statusText); }
});
});
The response always states "OK : 200", and the response content is:
<?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/">Hello World</string>