I have a simple webmethod on an asp.net 2.0 application (using the 1.0 extensions not the 3.5 ajax extensions). I'm attempting to call the method from jQuery and when I do it as the countless examples show on the Internet and here on SO, I get an Internal Server Error message returned.
Here's my current code:
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public string Select(string login)
{
UserProfile profile = UserProfile.GetUserProfile(login);
return "{ FirstName: '" + profile.FirstName + "', " +
"LastName: '" + profile.LastName + "', " +
"EmailAddress: '" + profile.EmailAddress + "', " +
"PhoneNumber: '" + profile.PhoneNumber + "' }";
}
And now the jquery:
$.ajax({
type: "POST",
url: "Services/ProfileService.asmx/Select",
dataType: "json",
data: "{'login':'DOMAIN%5CUSER1'}",
contentType: "application/json; charset=utf-8",
success: function(msg){ alert(msg); },
error: function(xhr){ alert(xhr.statusText);}
});
The webservice is decorated with the [ScriptService]
attribute as well. If I comment out the contentType, change the dataType to text, and change the data to be a query string (name=value), I get the XML returned appropriately.
Where am I going wrong?
UPDATE: I am using jQuery v1.3.1 and testing in both IE6 and Firefox 3. I'm getting consistent results.