Difficulty loading a data var from external .js file

4 posts, 0 answers
  1. Andrew
    Andrew avatar
    6 posts
    Member since:
    Dec 2011

    Posted 17 Jan 2012 Link to this post

    Hi!

    I need to separate the datasource for my grid in a separate user updatable data file, called "datasource.js". 

    I have placed the call to the src in the head and it fails totally in Komodo Edit. When I place the src call in the body, it works in Komodo, but not in the browsers (Opera and Chrome).

    The data file looks like this:
    var data = [{"picture": "EnviroPopulation99.png","TaxiName": "Andrew's Taxis","TaxiPhone": "01239 289617"},
    {"picture": "Island Biogeography 99.png","TaxiName": "AllStar Taxis","TaxiPhone": "01249 241521"},
    {"picture": "MarkandRecapture99.png","TaxiName": "TaxiCars","TaxiPhone": "01249 275141"},
    {"picture": "Population Viability Analysis99.png","TaxiName": "01TaxiCabs", "TaxiPhone": "01249 275987"}];
    var testdata = "Hello data!";

    The code html file has the standard grid code calling data: data;

    The test variable at the bottom of the file works fine.

    Is there any reason why a data variable called from an external .js file using <script> would fail, please?

    All the best,

    Andrew.
  2. John DeVight
    John DeVight avatar
    209 posts
    Member since:
    Jan 2010

    Posted 18 Jan 2012 Link to this post

    Hi Andrew,

    I've tried recreating the problem, but have been unsuccessful. 

    Here is how I referenced the datasource.js:

    <script type="text/javascript" src="/Scripts/datasource.js"></script>


    Here is the code that I defined for the grid:

    $('#peopleGrid').kendoGrid({
        dataSource: { data: data },
        columns:
        [{
            field: 'TaxiName',
            title: 'Taxi Name'
        }, {
            field: 'TaxiPhone',
            title: 'Taxi Phone'
        }]
    });

    How does this compare to what you have defined for your grid?

    Regards,

    John
  3. Kendo UI is VS 2017 Ready
  4. Andrew
    Andrew avatar
    6 posts
    Member since:
    Dec 2011

    Posted 18 Jan 2012 Link to this post

    Hi John!
    Many thanks for giving this issue a go. I contacted Kendo Support and they looked at the complete code and reduced the <script> line to just that, no "text/javascript". They also addded a !DOCTYPE html command at the top. That's all as far as I could see.
    Apparently different browsers expect to see slight variations in code so now it runs fine in Opera and IE.
    Problem solved for me at least.

    Cheers,
    Andrew.
  5. John DeVight
    John DeVight avatar
    209 posts
    Member since:
    Jan 2010

    Posted 18 Jan 2012 Link to this post

    Glad to hear =)

    Regards,

    John DeVight
Back to Top
Kendo UI is VS 2017 Ready