PDA

View Full Version : Problem with fetching URL (periodically)



alex999
24 Jun 2009, 4:26 AM
Hello,

I try to call a .php file periodically. Therefore I implemented an Upater object like this:

function xy()
{
el = Ext.get("aaa");
mgr = el.getUpdater();
mgr.startAutoRefresh(3, 'status.php?ID=' + Ext.get('myid').getValue());
}
This is working.

If I try like this:

function xy()
{
el = Ext.get("aaa");
mgr = el.getUpdater();
mgr.startAutoRefresh(3)
mgr.on("update", myCallBackFcn);
}
function myCallBackFcn(){

var myId = Ext.get('myid').getValue();

var conn = new Ext.data.Connection();
conn.request({
url:'status.php',
method:'GET',
params: { ID: myId },
success: function(responseObject) {
},
failure: function() {
alert("Something fail");
}
});
}
I get this error:

uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://localhost/sites/extjs/adapter/ext/ext-base.js :: asyncRequest :: line 112" data: no]The funny thing is, if I mix both requests

mgr.startAutoRefresh(3, 'status.php?ID=' + Ext.get('myid').getValue());
// and also
mgr.on("update", myCallBackFcn);
//[...]
both requests are working alternately!?

I use extjs 3.0 RC2.

Thank you,
Alex

hendricd
24 Jun 2009, 6:49 AM
Hello,
I get this error:

uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://localhost/sites/extjs/adapter/ext/ext-base.js :: asyncRequest :: line 112" data: no]

That's because you're NOT passing a URL (thus undefined when the Request is made):

function xy()
{
el = Ext.get("aaa");
mgr = el.getUpdater();
mgr.startAutoRefresh(3, URL)
mgr.on("update", myCallBackFcn);
}
function myCallBackFcn(){

The UpdateManager Documentation likely needs to be expanded to indicate that you can also pass a Function for a params argument, permitting:



function xy()
{
el = Ext.get("aaa");
mgr = el.getUpdater();
mgr.startAutoRefresh(3, 'status.php', gatherParams, null, true);
}

function gatherParams (){
return {ID : Ext.get('myid').getValue() || 'unknown'}; //always send the current value
}

new2ext
24 Jun 2009, 6:51 AM
startAutoRefresh() only requires the interval. If you don't specify the url, the function will reuse the url from load(), but it will not reuse any other options. Your second scenario should look like

mgr.startAutoRefresh(3,{ ID: myId })


Your second scenario is also getting the update value twice.
on("update",myCallBackFcn) is an event that calls myCallBackFcn after an update. myCallBackFcn is requesting an update of the value right after it's been updated.

alex999
24 Jun 2009, 7:33 AM
UPDATE: ok, now it is working, there was a problem with mit response from the php file.
Furthermore I've seen that a callback function gets passed 2 or 3 params:

2 params in case of an event handler: function cb (el, response)
3 params in case of a real callback: function cb (el, success, response)
so I have the desired server-response.
Correct me if I'm wrong.

Thanks a lot!



**** next stuff was obsolete ! ****

hendricd
24 Jun 2009, 8:08 AM
As indicated in the documentation, the event receives two arguments:



function myCallBackFcn(el,response){
// fetch the .php file with Connection object to gather server response
alert(response.responseText);
}