PDA

View Full Version : UpdateManager always populates innerHTML



lkasdorf
6 Jul 2007, 7:51 AM
Perhaps someone can share a wee bit on insight on something that I'm having trouble grokking with Ext. I am very new to Ext, but quite experienced with js, ajax, dojo, mybic, etc.

I have worked through most of the tutorials, and have a decent understanding, and have begun converting a project over to ext. I am able to use the UpdateManager to call a php script, which gets some data and returns html. The problem I have is that UpdateManager seems geared toward directly populating the innerHTML of a div, and I don't always want to do that. Instead, I want to call a callback function, and deal with the response data (JSON) myself.

Example:
// display list of organizations
function displayOrgList()
{
var mgr = new Ext.UpdateManager('orgListDiv');
mgr.update("scripts/displayOrgList.php", "foo=bar", displayOrgListCb);
}

// this gets called, and oResponse contains whatever the php script returns
// but my 'orgListDiv' gets stuffed with the response- I don't want that!
function displayOrgListCb(oElement, bSuccess, oResponse)
{
alert("displayOrgListCb");
}

This works fine except that my 'orgListDiv' gets populated with the return data of my server script, and I don't want this in many situations.

UpdateManager is a member of the element object, so it is inherently tied to some element. Perhaps I just need to create a dummy element that is invisible, but this seems inelegant.

I have been searching the docs and forums and I know that what I want is obviously possible (since there is a lot of talk about using JSON- and you wouldn't stick JSON into innerHTML), but I've not yet seen how to suppress this.

Animal
6 Jul 2007, 8:07 AM
http://extjs.com/deploy/ext-1.1-beta2/docs/

See Ext.Ajax, specifically:

http://extjs.com/deploy/ext-1.1-beta2/docs/output/Ext.Ajax.html#request

lkasdorf
6 Jul 2007, 11:13 AM
So- I take it that UpdateManager is supposed to always write to innerHTML. I reckon it is really just a shortcut way of doing and ajax request when you want to do this.

I'm using Ext.lib.Ajax.request now and that works- but I have 2 questions:

1. In examples, and in the source of UpdateManager.js, as well as in my working code, request takes args as follows:

Ext.lib.Ajax.request(method, url, cb, params);

However in the docs on the request method (http://extjs.com/deploy/ext-1.1-beta2/docs/output/Ext.Ajax.html#request) the argument is simply an object:

public function request([Object options])

So- how am I to reconcile this and make good use of the docs?

2. Do I use Ext.lib.Ajax.request or Ext.Ajax.request? I saw a help discussion referring to this and left quite confused.

I'm enjoying this wonderful and vast toolkit and look forward to truly grokking it.

tryanDLS
6 Jul 2007, 11:31 AM
Ext.lib.Ajax and Ext.Ajax are two separate objects and the request methods have different arg lists. Ext.Ajax is the newly introduced singleton object to do requests and is probably the better choice b/c it provides some more functionality. Some of the examples may still use the old Ext.lib.Ajax call directly - internally Ext.Ajax.request calls Ext.lib.Ajax.request.

All that being said, there are some holes in the doc - the ext-base.js file (where Ext.lib.Ajax.request is located) is one of them, as it was just created. Feel free to report documentation issues in the sticky documentation bugs thread in the Bugs forum.