0

I tried in 2 ways:

saving the json on a var

var dataLog = JSON.stringify( {
  "clientId": "1",
  "sensor": "Temp",
  "dateStart": "2016-09-03 00:00:00",
  "dateEnd": "2016-09-03 00:59:59"
} );

$.post(data , {dataLog})
  .done(function( data ) {
  console.table(data);
});

and adding the same json directly into the data parameter

$.post( url, {
  "clientId": "1",
  "sensor": "Temp",
  "dateStart": "2016-09-03 00:00:00",
  "dateEnd": "2016-09-03 00:59:59"
})
  .done(function( data ) {
  console.log(data);
});

but none of the 2 options works, it is possible or im doing something wrong?

6
  • 2nd method should work IMO Commented Oct 4, 2016 at 2:05
  • What error is showing up for you? Commented Oct 4, 2016 at 2:07
  • 1
    Do you want the server to receive the data as JSON? Commented Oct 4, 2016 at 2:12
  • Second one looks fine. How are you accessing the data in the server? Commented Oct 4, 2016 at 2:13
  • i dont know what's wrong, this is the api response Object {descripcion: "No existen o faltan datos", respuesta: "false"}, that response it's if i write something bad or left an empty value, but i copy paste the same data into postman and it works, idk why on jQ does't Commented Oct 4, 2016 at 2:16

1 Answer 1

1

here one example

var promise = $.ajax({
            url: url,
            type: 'POST',
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: dataLog
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.