PageMethods, jQuery e JSON
Estou tentando chamar umPageMethod
usando jQuery assim:
[WebMethod]
public stataic string WebMethod(PostData data)
{
//DO WORK
return "a";
}
PostData
classe é a seguinte:
public class PostData
{
public string Guid{get;set;}
public string Action{get;set;}
public string Id{get;set;}
}
Estou chamando o método do jQuery assim:
$.ajax({
type="POST",
url: 'url',
data: JSON.stringify(b),
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (msg) {
var t = $(c).html();
$(c).html(t + "<br/>" + $.evalJSON(msg.d));
},
error: function (x, y) {
var t = $(c).html();
$(c).html(t + "<br/>" + $.evalJSON(x.responseText).Message);
}
});
Ondeb
é como:{"PostData":{"Guid":"b61dce32-690b-4409-b51a-a6012462e54e","Action":"Testing","Id":"3"}}
Estou recebendo este erro:
Invalid web service call, missing value for parameter: 'data'.
Se eu não ligarJSON.stringyfy
então eu recebo este erro:
Invalid JSON primitive: PostData.
Eu tentei isso também{"Guid":"b61dce32-690b-4409-b51a-a6012462e54e","Action":"Testing","Id":"3"}
mas ainda assim
Invalid JSON primitive 'Guid'
ou
Invalid web service call, missing value for parameter: 'data'.
dependendo se eu ligarJSON.stringify
ou não.
Eu também tentei
[WebMethod]
public static string WebMethod(string data)
mas não tenho onde.