Author Topic: Bug? dataModel contentType=application/json, but postData send "k=v&k=v" format  (Read 1342 times)

zhouqi

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 16
    • View Profile
When I config dataModel with "contentType: 'application/json'" as:

Code: [Select]
dataModel: {
location: 'remote',
url: '/news',
contentType: 'application/json; charset=UTF-8',
postData: {"author":"jack", "isTopic": 1},
dataType: 'JSON',
method: 'POST'
}


I found pqgrid ajax send data is "x-www-form-urlencoded" format (author=jack&isTopic=1), not JSON-String payload format ({"author":"jack", "isTopic": 1}).

In fact, ajax should send JSON-String payload format data use JSON.stringify(postData) when contentType is "application/json".

Now, I must config beforeSend to reset send data format:


Code: [Select]
beforeSend: function(xhr, settings) {
  settings.data = JSON.stringify({....});
}

Is this a bug?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
dataModel is dependent upon $.ajax to send remote requests.

setting contentType options sends only header without affecting the data format.

$.ajax works the same unless processData option is set to false.

https://api.jquery.com/jquery.ajax/

May be there is a need to add processData option to dataModel in order it to work as expected.