dataSource not reading remote data

5 posts, 0 answers
  1. Nana
    Nana avatar
    3 posts
    Member since:
    Jul 2015

    Posted 26 Nov 2015 Link to this post

    I am trying to read json data from a remote service and its not working.

    my code: 

     

    var schema = {
                        data: "data",
                        model: {}
                    };
    var warmup = new kendo.data.DataSource({
                        schema: schema,
                        transport: {
                            read:  function(options) {
                                    $.ajax( {
                                        url: kendo.toString(baseUrl + wkdayID),
                                        success: function(result) {
                                            console.log(kendo.toString(baseUrl + wkdayId));
                                            options.success(result);
                                        }
                                    });
                                }
                        },
                        filter: { field: "IS_WARMUP", operator: "eq", value: "1" },
                        error: function() {
                            console.log(arguments); }
                    });
     
                    warmup.fetch();

     

     

    however when I modify the url portion to a string and add it to the baseUrl  like this: 

    url: kendo.toString(baseUrl + "21")

    it works for some reason. does anyone know whats going on? I would like to be able to set that "21" dynamically. 

  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 27 Nov 2015 Link to this post

    Hello Nana,

     

    From The provided information we cannot tell you what exactly is the issue. So please provide some more information like - what is the baseUrl? Did you see any errors in the console? Is a request being made, by checking the network tab of the browser's developer tools?

     

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Nana
    Nana avatar
    3 posts
    Member since:
    Jul 2015

    Posted 27 Nov 2015 in reply to Kiril Nikolov Link to this post

    I looked at the network tab in chrome and it seems like the request is being sent. I attached a screenshot below.  baseUrl is just a variable I declared and I concatenate numbers to it to pull data from my database through php.

    //get today's date
    app.todayView = kendo.observable({
        onShow: function() {
         },
        afterShow: function() {
        }
    });
    // START_CUSTOM_CODE_todayView
       var schema = {
                        data: "",
                        model: {}
                    };
        //get the data for todays warm up
        var warmup = new kendo.data.DataSource({
                        schema: schema,
                        transport: {
                            read:  function(options) {
                                    // make AJAX request to the remote service
                                    $.ajax( {
                                        dataType : "jsonp",
                                        url: baseUrl + // add ID here to pull data,
                                        success: function(result) {
                                            // notify the DataSource that the operation is complete
                                            options.success(result);
                                        }
                                    });
                                }
                        },
                        filter: { field: "IS_WARMUP", operator: "eq", value: "1" },
                        error: function() {
                            console.log(arguments); }
                    });
     
                    warmup.fetch();

    I changed from json to jsonp but that did not make a difference. I hope this makes more sense what I am trying to accomplish. Maybe there is a better way to do this.

  5. Nana
    Nana avatar
    3 posts
    Member since:
    Jul 2015

    Posted 30 Nov 2015 Link to this post

    same thing is happening in a different one of my views in my app. When I configure the url portion of my dataSource directly with the url like "url:'someurl.com/php?var=2' "it works. But when I switch it to "url: url" where url is set at the beginning of the program it throws and error.

    code that doesnt work:

    'use strict';
     
    var url;
    app.weekView = kendo.observable({
        beforeShow: function(){
             if(localStorage.getItem('sportID') == 0){
                if(localStorage.getItem('phaseID')==0){
                    app.mobileApp.navigate("#:back");
                }
            }
        },
        onShow: function() {
            url = "http://host.com/service/retrieve_work_days.php?phaseid=21"; //localStorage.getItem("phaseID");
            console.log(url);
        },
        afterShow: function() {}
    });
     
    // START_CUSTOM_CODE_weekView
     var schema = {
                        model: {
                            id: "RECORD_ID",
                        }
                    };
     
                    var wkdays = new kendo.data.DataSource({
                        schema: schema,
                        transport: {
                            read: {
                                url: url,
                                dataType: 'jsonp',
                            }
                        },
                        sucess: function(){console.log("sucess")},
                        error: function() { console.log(arguments);}
                    });
                    wkdays.fetch();
                     
    // END_CUSTOM_CODE_weekView

    what's the difference?

  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 01 Dec 2015 Link to this post

    Hello Nana,

     

    For sending parameters to the server you need to use the parameterMap option, as explained here:

     

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.parameterMap

     

    Regards,
    Kiril Nikolov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready