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

Sending parameters in a POST for JSON?

3 Answers 1498 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Champ
Top achievements
Rank 1
Champ asked on 28 Oct 2011, 04:43 PM
Hi,

I am using CodeIgniter on my backend to return a JSON result, depending on parameters sent via a POST. I wanted to directly link the result to a Grid, via a DataSource. However, I am having problems either understanding DataSources, or how they pass parameters.

In the examples, you provide:
var dataSource = new kendo.data.DataSource({
    transport
: {
        read
: {
           
// the remote service URL
            url
: "http://search.twitter.com/search.json",
           
// JSONP is required for cross-domain AJAX
            dataType
: "jsonp",
           
// additional parameters sent to the remote service
            data
: {
                q
: function() {
                   
return $("#searchFor").val();
               
}
           
}
       
}
   
}
 If I want to test this, I simply use a browser to check "
http://search.twitter.com/search.json?q=whatever
" and it returns what would appear in the DataSource above.

The problem is that CodeIgniter does not accept parameters in the form of "?q=whatever" as standard. It can, however, accept GET and POST information.

How can I do it? I have a few theories:

1. set up the DataSource correctly to pass the parameters in a GET or POST (how?)
2. do not use a DataSource, but a javascript object to bind to the Grid (seems like a waste, how is this done?)
3. extend DataSource like you did with odata to make a special class that knows how to handle parameters in GET/POST.

What would you recommend?

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 31 Oct 2011, 08:35 AM
Hi Champ,

The ?q=whatever query string is, in fact, the way to pass a GET parameter to the server. CodeIgniter should recognize and parse it correctly. You can even access it using vanilla PHP - $_GET["q"] should return "whatever".  

Kind regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
wizmagister
Top achievements
Rank 2
answered on 23 Nov 2011, 10:09 PM
Alright but is there a way to do it with POST ?

I'm using a WebServices. So the question is how do I convert something like this for Kendo:
                  $.ajax({
                      type: "POST",
                      url: "StaticData.asmx/GetSomething",
                      data: null,
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      async: false,
                      success: function(msg) {
                         alert("success");
                      }
                  });

Do I use kendo directly ? or I fill up my dataSource with jQuery and then set it up to the Kendo Control ...

Thanks !

[UPDATE]
I just found that other thread: (not solved though)
http://www.kendoui.com/forums/framework/data-source/problem-with-datasource-post-request-for-read-operation.aspx
0
Atanas Korchev
Telerik team
answered on 24 Nov 2011, 08:38 AM
Hi Marc,

 You can pass the same settings to the datasource:

transport: {
    read: {
          type: "POST",
          url: "StaticData.asmx/GetSomething",
          data: null,
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          async: false
    }
}

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Champ
Top achievements
Rank 1
Answers by
Petyo
Telerik team
wizmagister
Top achievements
Rank 2
Atanas Korchev
Telerik team
Share this question
or