I have a Web Service that recive an JSON Object Prueba
public class Prueba
{
public string valor1 { get; set; }
public string valor2 { get; set; }
}
public JsonResult Pruebas(Prueba item)
{
string metodo = Request.HttpMethod;
return Json("error", JsonRequestBehavior.AllowGet);
}
And I want to call to the web service with JQuery:
$.ajax({
type: 'Post',
dataType: 'json',
url: 'http://localhost:24780/Api/Pruebas',
data:'{"valor1":"a","valor2":"b"}',
contentType: 'application/json; charset=utf-8',
success: function (data) {
console.debug(data);
},
error: function (data) {
console.debug(data);
}
});
The problem is that Request.method takes the value OPTION instead of POST. Also the object value is null.
I have tested the web service with SOAP UI without problems but I can't find why it don't work with JQuery.