PDA

View Full Version : UpdateManager and ext newbi...



TopKatz
5 Feb 2007, 9:26 AM
Hello all!

First Jack has obviously put a termendous amount of work into this framework, and it shows.

I am however having some trouble transitioning from using prototype to Jacks UpdateManager. IM basicaly trying to recreate some old scripts to get the hang of it, and I'm failing to grasp what Im doing wrong.

I have a simple ajax request I did with prototype using ajax.request. It grabs a zip code froma form, and passes it to a php script that does a look up, and returns a string with the city,state. I then split the string and populate two form elemnts with the results.

I have Update.Manager succesfully getting the result, and calling a function, but it does not seem to have be gettign the result, although firebug says Im getting the result.

Here is my code:

function newRequest(){

var el = getEl('zip');
var mgr = el.getUpdateManager();
mgr.update({url:'getCityState.php',params:{ zip: '02148'}, callback: printResult});

}

function printResult(oElement, oResponse){
var response = oResponse.responseText;
alert(oResponse.responseText);
}


Basicaly just sending getCityState.php a zipcode number 02148, it finds Malden,Ma. It returns it, and it should produce an alert that prints the string back. It does not seem as though my result is tied back to my object, however I don't see what Im missing. Can the update.manager function this way? Am I going about this all wrong? Any help would be apreciated.

Katz

tryanDLS
5 Feb 2007, 9:38 AM
Use firebug to stop in printResult to look at the response object. Are you even getting there? It may be a scoping issue as updateMgr has to be able to see the printResult fn

TopKatz
5 Feb 2007, 10:33 AM
I put a stop on the printResult line. oResponse has a value of "Object dom=input#zip id=zip visibilityMode=1", and responseText is undefined.

Im not sure what IM doing wrong. printResult is defenitly getting called, as my allert is comming up.

TopKatz
5 Feb 2007, 10:39 AM
Am I using update correctly? I jsut tweekd my callback a little and got something interesting. I added oElement to the function, so it looks liek this now

function printResult(oElement, oResponse)

now when I do alert(oResponse) I get "true". If I add alert(oResponse.responseText I get "unasighned". Will update return text objects, or is it only used to "update", and return a true or false response? If that is the case, what should I be using to handle response text if not update?

tryanDLS
5 Feb 2007, 12:50 PM
update is just going to dump the response into the requested element. Your callback is invoked as


urFunc(el, success)


after the element is updated. The newest version of UpdateManager passes the response as a 3rd arg to the callback, so you could do something else with it in your CB.

If you want do something other than dump the response into the target element, you can override the UpdateManager's default render fn via setRenderer and do whatever you want.

However, since you really want to get a result and do more processing, rather than use updateManager, you could just asyncRequest and process the result as you wish, without updating the element.

aconran
5 Feb 2007, 12:57 PM
If you simply want to Update the element you have a reference to with the UpdateManager follow the advice on this thread:
http://www.yui-ext.com/forum/viewtopic.php?t=2348


printResult will become your render method in a new class of MyRenderer

TopKatz
5 Feb 2007, 2:20 PM
I get it now.

I just built the markup into the response.

Thanks guys.