I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have:
I have a custom class named Default_county_init_data that, upon initialization makes several Ajax.Request calls to gather data from the server.
What I'm having trouble with is getting the data from the Ajax call back to the custom class instance. I basicially want to get a Javascript array from my PHP page and insert that into the custom class instance once the Ajax call is done.
Here is the most logical way I could think to do it (but it doesn't work):
Expand|Select|Wrap|Line Numbers
- var Default_county_init_data = Class.create({
- initialize: function(name){
- this.name = name;
- this.consumables = new Ajax.Request('http://www.stage.emd.wa.gov/dev/get_csv.php?county=' + this.name + '&cat=consumables',
- {method: 'get', onSuccess: function(e){
- return eval(e.responseText);
- }
- });
- . . .
- }
- }
I've also tried setting the value within the onSuccess method-- something like:
this.consumables = eval(e.responseText);
This doesn't seem to work, either, and I'm unclear what 'this' really is at this point in the code (I don't think it's my custom class instance anymore).
Is this an issue with binding (which I've not figured out how to use yet)? I have the Bungee Book which discusses this, it looks like I would want something like this for my onSuccess function:
Expand|Select|Wrap|Line Numbers
- new Ajax.Request.bind(this, 'http://www.stage.emd.wa.gov/dev/get_csv.php?county=' + this.name + '&cat=consumables',
- {method: 'get', onSuccess: function(e){
- this.consumables = eval(e.responseText);
- });
I would greatly appreciate any suggestions, this app can be viewed at this URL:
http://www.stage.emd.wa.gov/dev/donations.htm
thanks!