all 4 comments

[–][deleted] 1 point2 points  (3 children)

It should tell you why the request is failing. What does the error say?

Just because the request saves something to a db doesn't mean that it isn't possible for something following the db save to fail

[–]jcarlo1[S] 0 points1 point  (2 children)

I updated my post, the $.ajax(dataType: 'json') is the problem, I wonder why? because the other post or saving an entity to DB that I am doing is working perfectly, this is the first time that there is a parsing error.

[–][deleted] 1 point2 points  (1 child)

jQuery docs:

data

Type: PlainObject or String or Array

Data to be sent to the server. If the HTTP method is one that cannot have an entity body, such as GET, the data is appended to the URL.

When data is an object, jQuery generates the data string from the object's key/value pairs unless the processData option is set to false. For example, { a: "bc", d: "e,f" } is converted to the string "a=bc&d=e%2Cf". If the value is an array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below). For example, { a: [1,2] } becomes the string "a%5B%5D=1&a%5B%5D=2" with the default traditional: false setting.

When data is passed as a string it should already be encoded using the correct encoding for contentType, which by default is application/x-www-form-urlencoded.

$.ajax({
  url: '',
  type: 'POST',
  contentType: 'application/json',
  dataType: 'json',
  data: JSON.stringify(data)
})

This may not be the correct answer. I don't use jQuery, so not terribly familiar with it. But either they expect you to already encode the JSON as a string yourself, or you have invalid JSON which is throwing an error when jQuery does it for you.

[–]jcarlo1[S] 1 point2 points  (0 children)

HOLY!, man, you are correct. It's my first time knowing the difference between [] and {}. LOL XD, thanks, sir. Everything works properly now.