JS para WebAPI:
var _data = {
"NmCliente": "Dados",
"DsEmail": "e34816d43923dc8d779"
};
$.ajax({
data: JSON.stringify(_data),
type: "POST",
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: true,
complete: function (data) {
var _return = $.parseJSON(data.responseText);
alert(_return.DsEmail);
//debugger;
//console.log(data);
},
error: function (response) {
console.log(response.responseText);
}
});
JS para WebMethod:
var _data = {};
_data.nome = "anderson1";
_data.segundoNome = "bueno";
$.ajax({
data: JSON.stringify(_data),
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
crossDomain: true,
success: function (data) {
var _return = $.parseJSON(data.d);
alert(_return.Nome);
},
error: function (req, status, error) {
alert(2);
alert(error);
//alert(req.responseText);
}
});
Crossdomain
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
</system.webServer>