This is a migrated thread and some comments may be shown as answers.

Grid not populating when using POST transport

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 30 Dec 2014, 11:55 AM
Hi,

I have been using the Grid php wrapper for a few days in a new web project. Most of it work fine, except one thing, to which I can't find the solution.

I followed the examples to set up a simple Grid using remote data, formatted as JSON, through a crud.php file. The problem is that when I use POST transport type to read data, the Grid won't show anything (even though my crud.php file returns a correct JSON result). The Grid works fine if I don't use POST to read data. However, create, update and destroy commands work fine with POST.

Here is the code :
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url('users.crud.php?do=read')
    ->contentType('application/json')
    ->type('POST');  // If I remove this line, the Grid works, otherwise it's empty
 
// [...create, update, destroy use POST type...]
 
$transport = new \Kendo\Data\DataSourceTransport();
$transport->create($create)
    ->read($read)
    ->update($update)
    ->destroy($destroy)
    ->parameterMap('function mapParamsToJSON (data){return kendo.stringify(data);}');


The JSON data is just like this :
{"data":[{"id":"6","username":"Tom","password":"xxxxxx"}]}


I could use my Grid with GET, but for obvious security reasons I'd rather not.

Any idea would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 01 Jan 2015, 09:50 AM
Hi,

The Grid doesn't do a lot with the request type setting beside forwarding it to $.ajax.
You can try requesting the data directly to exclude the grid out of the loop.

For example, using the browser console:
$.ajax({
  url: "users.crud.php?do=read",
  type: "POST",
  contentType: "application/json"
}).done(function(data) {
  console.log("Success");
  console.log(data);
}).fail(function(xhr, status) {
  console.log("Error: " + status);
});

If reading the data this way works then we can move forward to debug any issues with the widget itself.

Happy New Year, wishing you a productive 2015!

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or