Welcome Guest, Not a member yet? Register   Sign In
Correct url to controller from kendo datasource
#1

[eluser]Unknown[/eluser]
I am brand new to both CodeIgnitor and KendoUI. I used to wrote a lot of components in Joomla and are therefore familiar with the MVC framework. I also used another (pretty lousy) js ui and therefore do know the principles of using these platforms.

I want to switch over to CodeIgnitor/KendoUI as quickly as possible and made some good progress but got stuck on a particular point. My index file is situated in:
[my website]/cabinet/index.php.
I do have the following directory structure:
[my website]/cabinet/application/controllers
[my website]/cabinet/application/models
[my website]/cabinet/application/views
[my website]/cabinet/application/config and so on.

In the views directory I do have:
[my website]/cabinet/application/views/customers/view.php
[my website]/cabinet/application/views/templates/header.php
[my website]/cabinet/application/views/templates/footer.php

In view.php is my kendo js and it loads fine except for getting the data for the datasource.

I do have the following code:

Code:
$("#customersGrid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "/index.php/customers/get_customers",
                        dataType: "json"
                    }
                },

but it seems not to reach my controller. I tried different versions of the url, but no joy.


Can anyone help me with what I should use so that I will be able to load the data through the controller?


#2

[eluser]Sudz[/eluser]
Hi,

Define a variable in your js and set it to your domain name like below
Code:
var SITEROOT = "www.yourdomainname.com";

// and now set url like this
$("#customersGrid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url:  SITEROOT + "/index.php/customers/get_customers",
                        dataType: "json"
                    }
                },


If you have removed index.php from your url then your code will be like this
Code:
$("#customersGrid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: SITEROOT + "/customers/get_customers",
                        dataType: "json"
                    }
                },
#3

[eluser]Unknown[/eluser]
Thank you for the response.

The problem is that after calling the grid from the kendo menu and the ajax call in my original scenario, the ajax request looked something like this:

Code:
index.php/customers/view/index.php/customers/get_customers

Therefore the ajax request was chained to the original grid request.

When using your suggestion the situation was similar, the only difference was that the code looked as follow:

Code:
[my domain]index.php/customers/view/[my domain]index.php/customers/get_customers

BUT

that give me enough ideas and after I used:

Code:
dataSource: {
                transport: {
                    read: {
                        url: "/cabinet/index.php/parcels/get_contents",
                        dataType: "json"
                    }
                },

for the ajax call and only

Code:
index.php/parcels/get_contents

for the grid call, it works!!

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB