jQWidgets Forums
jQuery UI Widgets › Forums › Grid › AJAX POST vs. Grid POST
Tagged: ajax post
This topic contains 4 replies, has 3 voices, and was last updated by Luis 4 years, 8 months ago.
-
AuthorAJAX POST vs. Grid POST Posts
-
Hello,
I am trying to have my grid get the headers and data from the same route based on a couple of keys I send through. For some reason, the grid is sending the data in a different (GET I think) format than the Ajax. Here’s some of the source:
MY AJAX:
$.ajax({
type: “POST”,
url: url,
data: JSON.stringify(myData),
dataType: “json”,
contentType: “application/json; charset=utf-8”,
complete: function(response){
What is sent to the server (inspected in browser – request payload):
data: “xxx”
expansion: “xxx”
grid: “xxx”
module: “xxx”GRID AJAX:
var mySource =
{
type: “POST”,
url: url,
data: myData,
datatype: “json”,
contenttype: “application/json; charset=utf-8”,
datafields: myDatafields,
root: “rows”,
filterscount=0&groupscount=0&pagenum=0&pagesize=10&recordstartindex=0&recordendindex=10&module=xxx&expansion=xxx&grid=xxx&data=xxxIf I JSON.stringify this, it ends up being garbage.
Is there any way I can use the grid AJAX to send my POST properly?Thanks
Hi mcfloyd,
If type: “POST” is set, the Grid will use POST instead of GET. If you want to format the data sent to the server, you may implement the jqxDataAdapter’s formatData callback function.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI can’t seem to change the format of the data going to the server. When I console.log inside the formatData method, it looks like what I should be sending to the server an object with all of its properties, but then it still sends it as param1=1¶m2=2¶m3=3&etc…
Any ideas how to do this?
Ah nevermind I got it!
I did a
var settings = {
formatData: function(data){
data = JSON.stringify(data);
return data;
}
}
var myDataAdapter = new $.jqx.dataAdapter(mySource, settings);Thank you mcfloyd, I was struggling a couple of days with this. Your solution worked perfectly. This one is a bit shorter:
var dataAdapter = new $.jqx.dataAdapter(source, { formatData: function (data) { return JSON.stringify(data); }, });
-
AuthorPosts
You must be logged in to reply to this topic.