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

dataSource not reading remote data

4 Answers 395 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Nana
Top achievements
Rank 1
Nana asked on 26 Nov 2015, 09:20 PM

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. 

4 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 27 Nov 2015, 09:13 AM

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!
 
0
Nana
Top achievements
Rank 1
answered on 27 Nov 2015, 07:16 PM

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.

0
Nana
Top achievements
Rank 1
answered on 30 Nov 2015, 05:56 PM

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?

0
Kiril Nikolov
Telerik team
answered on 01 Dec 2015, 09:03 AM

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!
 
Tags
Data Source
Asked by
Nana
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Nana
Top achievements
Rank 1
Share this question
or