1
I have the following variable:
json_sending = JSON.stringify(obj);
the value of the:
"{"usuario":
{"login":"gleyson",
"senha":"1"},
"razao_social":"INTELIDER",
"nome_fantasia":"INTELIDER LTDA",
"cpf_cnpj":"10999558000186",
"rg_insc_estadual":"11111",
"tipo":"F"}"
I am using Jquery Ajax to send, however, this falling in the exception of the code below:
$.ajax({
type: "POST",
url: "http://localhost/api/pessoas",
dataType: "json",
async: false,
data: json_envio,
success: function (result) {
alert('tudo certo');
},
error: function (exception) { alert('Exeption:' + JSON.stringify(exception)); }
The error is as follows:
Exeption:{"readyState":4,"responseText":"{\"Message\":\"
A solicitação é inválida.\",\"ModelState\":{\"pessoa.tipo\":[\"O campo tipo
é obrigatório.\"],\"pessoa.razao_social\":[\"O campo razao_social é
obrigatório.\"]}}","responseJSON":{"Message":"A solicitação é
inválida.","ModelState":{"pessoa.tipo":["O campo tipo é
obrigatório."],"pessoa.razao_social":["O campo razao_social é
obrigatório."]}},"status":400,"statusText":"Bad Request"}
I understood that he is complaining about the type and social razao_field, however, both are in Json that is in the json_send variable and taking the value of it and using soapUI, I can send without problem. What could be wrong?
image of obj value:
Why convert json object to string if dataType is json? I don’t seem to need
JSON.stringify(obj);
– BrTkCa
@Lucascosta O
dataType
defines the type of data expected in the server response, not from the data sent to the server.– Woss
The question is: what code on
/api/pessoas
?– Woss
@Andersoncarloswoss is a Webapi service, but if I can send by souap should I not be able to send by ajax as well? You want me to enter the entity code and the controller?
– Gleyson Silva
Yes. You came to check which data comes in the API this way?
– Woss
@Intelidersistemas can send only
obj
in thedata:
. jQuery already converts it, so you don’t needJSON.stringify(obj)
– Sergio
@Sergio added the image I picked up in the debug of Chrome in my question
– Gleyson Silva
good idea @Andersoncarloswoss, I’ll look here.
– Gleyson Silva
@Sergio was just that, I sent directly the object without the JSON, Stringify and passed blz. thanks for the attention!
– Gleyson Silva