PDA

View Full Version : Callback problems using Codeigniter and ScriptTagProxy



scottmartin
13 Sep 2010, 2:21 PM
I am trying to get my grid to load data using ScriptTagProxy. I am able to see the JSON records in FB:Net:HTML:Response.

Under Params I see stcCallback1001. The GET is displaying the param as:


http://10.0.0.100/bms-hr/index.php/users/list_users/?_dc=1284415387926&callback=stcCallback1001store info:



var remoteProxy = new Ext.data.ScriptTagProxy({
api: {
read : 'index.php/users/list_users/',
create : 'index.php/users/insert_users/',
update: 'index.php/users/update_users/',
destroy: 'index.php/users/delete_users/'
}
});

var dataStore = new Ext.data.JsonStore({
proxy: remoteProxy,
root: 'users',
autoLoad: true,
autoSave: false,
successProperty : 'success',
totalProperty : 'totalCount',
messageProperty: 'message',
idProperty: 'id_user',
writer: writer,
fields: userFields
});

CI:Controller: users.php



function list_users() {
$data = json_encode($this->User_model->list_users());
$cb = isset($_GET['callback']) ? $_GET['callback'] : '';
print $cb . '(' . $data . ')';
}
$_GET['callback'] is not returning a value from my controller file.

Is CI causing this, or my code?

Regards,
Scott.

scottmartin
15 Sep 2010, 4:38 AM
FYI,
Seems CI disables _GETS. I used _REQUEST and all is well.

Regards,
Scott.

Animal
15 Sep 2010, 4:48 AM
But why are you using a ScriptTagProxy? I see relative URLs there which will go to the page's origin domain.

scottmartin
15 Sep 2010, 5:22 AM
Animal,

I 'thought' I read in the forums this was the preferred method in my approach. Could I get you to explain in more detail on why this not correct? Should I be using httpProxy?

I am still trying to decipher ExtJS as I go. (even after numerous rtfm sessions)

Thanks for the help!

Regards,
Scott.

Animal
15 Sep 2010, 6:04 AM
Well it uses a <script> element to communicate. Which is why you are forced to pass the data into a callback: The result must be executable Javascript.

if you used an HttpProxy, you just return JSON.

scottmartin
15 Sep 2010, 6:26 AM
Animal,

Thanks for the tip. For anyone watching:



var proxy = new Ext.data.HttpProxy({
method: 'POST',
url : 'index.php/employees/list_employees/'
});


This also follows CI in not using GET approach.

Regards,
Scottl