I created the following function to send an object of a service through JSON but when the object arrives it has all the empty variables:
var cpDate = new Object();
cpDate = {
OllPass: '',
NewPass: '',
ConfPass: ''
};
$(document).ready(function () {
// Guardar Contraseña
$('#btnAceptarCP').click(function () {
ChangePass();
});
});
function ChangePass() {
cpDate.OllPass = $('#txtOllPass').val();
cpDate.NewPass = $('#txtNewPass').val();
cpDate.ConfPass = $('#txtCPass').val();
}
$.ajax({
type: "POST",
url: '../Servicio/Servicio_Prueba.asmx/setContrasena',
data: JSON.stringify({ solicitud: cpDate }),
contentType: "application/json",
async: false,
dataType: "json",
success: function (result) {
alert(result.d);
},
error: function (result) {
//Log the error to the console
}
});
Service where I expect the object:
public class Servicio_Prueba : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
public object setContrasena(EntidadPass solicitud)
{
bool guardado = true;
solicitud.setContrasena(solicitud);
return guardado;
}
}
EntidadPass
:
public class EntidadPass
{
string OllPass { get; set; }
string NewPass { get; set; }
string ConfPass { get; set; }
public void setContrasena(EntidadPass solicitud)
{
}
}
What I want to know is why the variables arrive empty.