Kendo DataSource (AJAX) "GET" / Custom Query

3 posts, 0 answers
  1. Damien
    Damien avatar
    8 posts
    Member since:
    Jan 2013

    Posted 03 Feb 2013 Link to this post

    Below is a data source which connects to an external REST service. All is well, except when I want to do a query and not return the entire set of data. I need to URL encode with messageTo = xxx but I am unsure of the correct syntax in a Kendo datasource or if this is supported at all..

    Are you able to assist? Source code below. The code in BOLD is not working

    Best Regards,

    Damien.


    var dataSource = new kendo.data.DataSource({
                serverPaging: true,
                pageSize: 10,
                transport: {
                    read: {
                type: 'GET',
                headers: {'X-Parse-Application-Id':'MY_AUTH_KEY','X-Parse-REST-API-Key':'MY_SECOND_KEY'},
                url: "  https://api.parse.com/1/classes/Messages",
                data: "{ messageTo: 'USER_ID_HERE'}",
     
                dataType: "json" // JSONP (JSON with padding) is required for cross-domain AJAX
                    },
                 
                },
                schema: { // describe the result format
                    data: "results" // the data which the data source will be bound to is in the "results" field
                }
            });
  2. Damien
    Damien avatar
    8 posts
    Member since:
    Jan 2013

    Posted 04 Feb 2013 Link to this post

    Here is the code Parse.com has recommended for the REST API
    
    
    I have tried everything and cannot get this to work!!!! 
    All I want to do is specify additional query options instead of returning everything!!!!!
    
    $.ajax({
      type: 'GET',
      headers: {'X-Parse-Application-Id':'PARSE-APP-ID','X-Parse-REST-API-Key':'PARSE-REST-KEY'},
      url: "https://api.parse.com/1/users",
      data: 'where={"username":"someUser"}',
      contentType: "application/json"
    });
  3. Daniel
    Admin
    Daniel avatar
    2230 posts

    Posted 06 Feb 2013 Link to this post

    Hello Damien,

    The dataSource transport operations are just a wrapper for the jQuery ajax method so generally you should be able to use the same approach. If the parameters should be send in JSON format then you should rather use the transport parameterMap function to add them to the request e.g.

    transport: {
        read: {
            type: 'GET',
            headers: { 'X-Parse-Application-Id': 'MY_AUTH_KEY', 'X-Parse-REST-API-Key': 'MY_SECOND_KEY' },
            url: "https://api.parse.com/1/classes/Messages",               
            dataType: "json" // JSONP (JSON with padding) is required for cross-domain AJAX
        },
        parameterMap: function (data, operation) {
            return kendo.stringify({ messageTo: "USER_ID_HERE" });
        }
    }
    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top