The main problem is that you are returning JSON data in the HTTP header, and not as the content of the response. You probably want to do something like this:
Response.ContentType = "application/json";
Response.Write(result);
Response.End();
, ASPX-. , Page_Load, , , - JSON. , JSON .
JSON , ASP.NET AJAX " ", . :
public class PermissionsResult
{
public bool success;
public string message;
public int user_level;
public List<Switch> switches;
}
public class Switch
{
public int number;
public bool is_enabled;
public bool is_default;
}
[WebMethod]
public static PermissionsResult GetPermissions(int UserLevel)
{
PermissionsResult result = new PermissionsResult();
result = YourBusinessLogic.GetPermissionsByLevel(UserLevel);
return result;
}
, , , . , , .
ASP.NET AJAX jQuery, $.ajax() :
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
url: 'MyPage.aspx/GetPermissions',
data: JSON.stringify({ UserLevel: 1}),
data: "{'UserLevel':" + $('#UserLevel').val() + "}",
success: function(data) {
$('#testp').append(data.d.message);
}
});
, : http://encosia.com/2010/05/31/asmx-scriptservice-mistake-invalid-json-primitive/
, JSON.stringify(): http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/
.d - , . , JSON , :
{"d": { "success": true, "message": "SUCCESS", "user_level": 25, "switches": [ { "number": 30, "is_enabled": false, "is_default": false }, { "number": 30, "is_enabled": false, "is_default": false } ]}}
, . , , . , , . : http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/