[Proto-Scripty] Ajax functions not working inside classes.
The following code works: new Ajax.Request('somefile.php',{ method:'get', onSuccess: function(transport){ var response = transport.responseText || no response text; alert(Success! \n\n + response); }, onFailure: function(){ alert('Something went wrong...') } }); however, if you encapsulate the code inside a class: var myclass = Class.create({ cut and paste exact same code into here }); var thisclass = new myclass(); thisclass.submit(); The code ALWAYS comes back with an empty response when you encapsulate the AJAX call :( Any ideas what I am doing wrong? is prototype broken? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Ajax functions not working inside classes.
Hi, is prototype broken? No, I use Ajax functions within classes all the time. however, if you encapsulate the code inside a class: var myclass = Class.create({ cut and paste exact same code into here }); If I cut and paste exact same code into here I get this: var myclass = Class.create({ new Ajax.Request('somefile.php',{ method:'get', onSuccess: function(transport){ var response = transport.responseText || no response text; alert(Success! \n\n + response); }, onFailure: function(){ alert('Something went wrong...') } }); }); ...which creates a new Ajax request immediately and passes it into Class.create, which is clearly not what you want. Try this: http://proto-scripty.wikidot.com/self-contained-test-page You'll probably figure out what you're doing wrong, and if not, you'll have a complete example to post when asking for help. -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Dec 6, 4:08 am, evilC ev...@evilc.com wrote: The following code works: new Ajax.Request('somefile.php',{ method:'get', onSuccess: function(transport){ var response = transport.responseText || no response text; alert(Success! \n\n + response); }, onFailure: function(){ alert('Something went wrong...') } }); however, if you encapsulate the code inside a class: var myclass = Class.create({ cut and paste exact same code into here }); var thisclass = new myclass(); thisclass.submit(); The code ALWAYS comes back with an empty response when you encapsulate the AJAX call :( Any ideas what I am doing wrong? is prototype broken? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Ajax functions not working inside classes.
Thanks TJ, I tried to make a self-contained version, so I ripped out prototype and did the same thing with object literals, and I still had issues, so clearly it wasnt prototype. In the end I figured out that the button which fired off the AJAX request (ie the Submit button) was inside a form (I did not want it to actually do an HTTP POST submission of the form, just call JS code) and I had not disabled the form with onsubmit='return false', so when I clicked submit, it was submitting the form, thus destroying the button that made the AJAX call before the reply came back. I had noticed that putting an alert or delay into the script caused it to work and was tearing my hair out - obviously the delay stopped the button being destroyed long enough for the AJAX request to come back. Oh the joys of Asynchronous web coding. I now have a slightly different problem, with the same button... Once the AJAX reply comes back that the data was updated, I want to destroy the form. But it won't let me. I guess for a similar reason to my explanation above - the button started the call, and it is in the response code that I wish to destroy it, so it technically hasn't finished yet. I hope that all makes sense. If not, I will try and rig some self contained code using the system you linked - I guess for the ajax request I could just get it to grab a css file or something off the server? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Ajax functions not working inside classes.
Instead of onSuccess, try using onComplete... -- Sent from my Palm Prē evilC wrote: Thanks TJ, I tried to make a self-contained version, so I ripped out prototype and did the same thing with object literals, and I still had issues, so clearly it wasnt prototype. In the end I figured out that the button which fired off the AJAX request (ie the Submit button) was inside a form (I did not want it to actually do an HTTP POST submission of the form, just call JS code) and I had not disabled the form with onsubmit='return false', so when I clicked submit, it was submitting the form, thus destroying the button that made the AJAX call before the reply came back. I had noticed that putting an alert or delay into the script caused it to work and was tearing my hair out - obviously the delay stopped the button being destroyed long enough for the AJAX request to come back. Oh the joys of Asynchronous web coding. I now have a slightly different problem, with the same button... Once the AJAX reply comes back that the data was updated, I want to destroy the form. But it won't let me. I guess for a similar reason to my explanation above - the button started the call, and it is in the response code that I wish to destroy it, so it technically hasn't finished yet. I hope that all makes sense. If not, I will try and rig some self contained code using the system you linked - I guess for the ajax request I could just get it to grab a css file or something off the server? -- You received this message because you are subscribed to the Google Groups Prototype amp; script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Ajax functions not working inside classes.
I have put up a version on my web server. http://www.evilc.com/pb The JS file is at http://www.evilc.com/pb/placebook.js - the code you are interested in will be in the pb_editloc object near the end. The HTML of the form is at http://www.evilc.com/pb/templates/pb_add_location.html (the php grabs this and passes it to the JS in the templates[] array) Here is how to replicate: 1. Click Add Location in the top right of the map window - This calls pb_editloc.add 2. Click the Point radio button in the form that appears. You are now in the form where the problem lies - with the submit/ cancel buttons at the bottom. Click on the map to place a marker and type a name in the name box to make the submit button light up. Once you click submit, it adds the location to the back end database fine, but when it calls pb_editloc.deleteform in the AJAX callback function (in pb_editloc.submit), it fails. Notice if you click Cancel, it kills the form fine. This ultimately calls pb_editloc.deleteform just like submit does, but I am presuming as there is no AJAX call still running that the button started, the button can be deleted. Thanks in advance for any help. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Ajax functions not working inside classes.
Just tried onComplete - no joy I uploaded a copy to http://www.evilc.com/pb/pb.zip, should anyone be so kind as to be inclined to take a look at it. If you have a localhost LAMP server (I use XAMPP) with default sql account of root/blank , it will work without any modifications - just create a database called placebook and inject the sql from the install folder. Else you may need to edit config.php if you have different db settings. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Ajax functions not working inside classes.
Hi, Once the AJAX reply comes back that the data was updated, I want to destroy the form. But it won't let me. I guess for a similar reason to my explanation above - the button started the call, and it is in the response code that I wish to destroy it, so it technically hasn't finished yet. No, that actually won't give you any trouble. No reason you can't remove the form from the response handler of an Ajax request initiated by an event handler on the form or one of its elements. ...wont' let [you] *HOW*? Specifics count for a lot, as does (again) a _small_ self-contained test page. The links you've put up are not to small self-contained stuff, but to largish stuff most people aren't going to bother to read through. Burn it down to the pure product, a few lines of code that do the thing (or don't do the thing), and you'll almost certainly figure it out -- and if not, again, you'll have something nice and small to post to ask for help with. -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Dec 6, 5:57 pm, evilC ev...@evilc.com wrote: Thanks TJ, I tried to make a self-contained version, so I ripped out prototype and did the same thing with object literals, and I still had issues, so clearly it wasnt prototype. In the end I figured out that the button which fired off the AJAX request (ie the Submit button) was inside a form (I did not want it to actually do an HTTP POST submission of the form, just call JS code) and I had not disabled the form with onsubmit='return false', so when I clicked submit, it was submitting the form, thus destroying the button that made the AJAX call before the reply came back. I had noticed that putting an alert or delay into the script caused it to work and was tearing my hair out - obviously the delay stopped the button being destroyed long enough for the AJAX request to come back. Oh the joys of Asynchronous web coding. I now have a slightly different problem, with the same button... Once the AJAX reply comes back that the data was updated, I want to destroy the form. But it won't let me. I guess for a similar reason to my explanation above - the button started the call, and it is in the response code that I wish to destroy it, so it technically hasn't finished yet. I hope that all makes sense. If not, I will try and rig some self contained code using the system you linked - I guess for the ajax request I could just get it to grab a css file or something off the server? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Ajax functions not working inside classes.
Hi, Just tried onComplete - no joy You probably don't want onComplete. onComplete is called regardless of whether the request was successful. You probably want onSuccess and onFailure, doing different things. -- T.J. On Dec 6, 7:25 pm, evilC ev...@evilc.com wrote: Just tried onComplete - no joy I uploaded a copy tohttp://www.evilc.com/pb/pb.zip, should anyone be so kind as to be inclined to take a look at it. If you have a localhost LAMP server (I use XAMPP) with default sql account of root/blank , it will work without any modifications - just create a database called placebook and inject the sql from the install folder. Else you may need to edit config.php if you have different db settings. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Ajax functions not working inside classes.
Also, in PHP related advice, *ereg *and *split* are deprecated. if you turned on your PHP errors and use E_ALL, it will throw back errors. Rick On Sun, Dec 6, 2009 at 6:36 PM, Rick Waldron waldron.r...@gmail.com wrote: Actually, my reasoning for that response was a fluke, so ignore it the problem: you're calling *this*.deleteform() I noticed you use all kinds of alert()'s for debugging... i'd recommend learning firebug and making it your very best friend. Firebug told me that *this* IS NOT *pb_editloc*, its actually *window* so... replace *this*.deleteform() with: *pb_editloc*.deleteform(); And it works perfectly. Also, can i recommend that you don't use body onload=foo()... its silly to wait that long to start doing your DOM work. I dropped the onload= attribute, and commented out the function it called (might as well delete it), but copied the body of it into document.observe('dom:loaded') Also... I made some suggestions in here. Find them in *bold* document.observe('dom:loaded', function () { * // Mixing elderly events with Prototype is sloppy. //window.onresize= winResize; document.observe('resize',winResize); * winResize(); pb_editloc.initialize(); var latlng = new google.maps.LatLng(51.64, 0); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map($(map_canvas), myOptions); // Click Listener google.maps.event.addListener(map, 'click', function(event) { if (pb_editloc.editmode){ pb_editloc.clicked(event.latLng); } }); // Insert sidebar * ** var newDiv = document.createElement(div); newDiv.innerHTML = ; newDiv.id =pb_sidebar; ** $(pb_rightbar).appendChild(newDiv); ** /* **// Why not use: ** $(pb_rightbar).insert( new Element('DIV', {id: 'pb_sidebar'}) ); */ * // Insert loc box (Shows current location) pb_locbox.initialize('pb_locbox','pb_bottombar'); // Insert zoom box (Shows current zoom) pb_zoombox.initialize('pb_zoombox','pb_bottombar'); // Insert zoom box (Shows current zoom) pb_zoombox.initialize('pb_wipe_database','pb_bottombar'); //Insert Add button insertHtmlFromTemplate(pb_add_location_button,pb_map_controls); readLocations(); }); On Sun, Dec 6, 2009 at 6:11 PM, Rick Waldron waldron.r...@gmail.comwrote: The problem is that when the dom is loaded... there is no such thing as pb_add_location. On Sun, Dec 6, 2009 at 5:09 PM, T.J. Crowder t...@crowdersoftware.comwrote: Hi, Just tried onComplete - no joy You probably don't want onComplete. onComplete is called regardless of whether the request was successful. You probably want onSuccess and onFailure, doing different things. -- T.J. On Dec 6, 7:25 pm, evilC ev...@evilc.com wrote: Just tried onComplete - no joy I uploaded a copy tohttp://www.evilc.com/pb/pb.zip, should anyone be so kind as to be inclined to take a look at it. If you have a localhost LAMP server (I use XAMPP) with default sql account of root/blank , it will work without any modifications - just create a database called placebook and inject the sql from the install folder. Else you may need to edit config.php if you have different db settings. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.