Author Topic: postData and stringify  (Read 2983 times)

lhohman

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 9
    • View Profile
postData and stringify
« on: July 04, 2019, 04:27:08 am »
I'm using dataModel.postData to send some parameters in a JSON back to the server, but these parameters are serialized and converted to a query string by "stringify" thus making this very hard for me to process on my python/django backend, where everything is handled as a JSON object.

According to the documentation setting option-stringify to false, should prevent the JSON to be serialized into a query string, but isnt working.

Getting as params:
Code: [Select]
pq_datatype=JSON&lastdate=2019-06-30&firstdate=2019-06-01&where_cond%5Baxe_code%5D=!null
Expecting:
Code: [Select]
{
"lastdate": "2019-06-30",
"firstdate": "2019-06-01",
"where_cond": {
"axe_code": "!null"
}
}

Docs consulted:

https://paramquery.com/pro/api#option-dataModel-postData

https://paramquery.com/pro/tutorial#topic-remote-requests

https://paramquery.com/pro/api#option-stringify
« Last Edit: July 04, 2019, 04:55:00 am by lhohman »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: postData and stringify
« Reply #1 on: July 04, 2019, 06:20:16 pm »
stringify option works fine, can be verified by using postData and setting stringify to true/false in this demo: https://paramquery.com/pro/demos/sorting_remote

How do you trigger the remote requests and do you use GET or POST requests?

Please share a small test case via jsfiddle so that I can look into it.

lhohman

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: postData and stringify
« Reply #2 on: July 04, 2019, 08:03:30 pm »
Hello thanks for your support, in the same example you provided I added postData datasample and set stringify to false: http://jsfiddle.net/bvkusx8j/

If you check on the console/network tab you can see that the data sample is sent as a query string and not a JSON

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: postData and stringify
« Reply #3 on: July 05, 2019, 04:54:05 pm »
JSON data can't be send as such and it's is first escaped and then send as query string.

It's send as query string for GET request and POST data for POST requests.

query string is different in both cases ( stringify true/ false ).

I don't have knowledge of python/django, but there might be functions to stringify / parse the JSON data server side.