Cool, thanks Daniel, very complete answer. All Daniel's points are valid, but just to focus more on the problem:
1. use the 'submit' event on the form; 2. use the correct id on your request.post function. Your form id is 'myform' and you are using 'ad-form'. -- Fábio Miranda Costa Solucione Sistemas Engenheiro de interface On Sat, Oct 17, 2009 at 10:54 AM, Daniel Lohse <[email protected] > wrote: > > Hey, > I'd like to help you. First, please use normal " for your html attributes > so it looks like this: > > <form action="save" id="myform" method="post"> > <input name="somefield" type="text" /> > <input type="submit" id="sub" /> > </form> > > Then in your script-Block it's type="text/javascript" and not > text="javascript"! > Then you'd better use the submit event of your form as you can cancel the > form submission from with it. > And please, e.stop() is all you need. Since MooTools 1.2 it's already an > Event instance so you don't need to instantiate it again. :) > > Furthermore, when you're using the 'post' method of the Request instance > you don't need the method: 'POST' parameter. > What you did forget was the method="post" in your HTML form, that is > needed. > > <script type="text/javascript"> > $('myform').addEvent('submit', function(e) { > e.stop(); > req = new Request.HTML({ > url: e.target.get('action'), > onSuccess: function (responseTree, responseElements, > responseHTML, responseJavaScript) { > alert(responseHTML); > } > }); > req.post($('myform')); > } > </script> > > So, I rewrote it partly. Test it and post here with any errors/questions. > > Also, please see that if errors occur you have a look into the Firebug > error console. > > > Cheers, Daniel > > > On 2009-10-17, at 17/October, 3:25 PM, rutherford wrote: > > >> I tried to do an ajax form post using the following code but the >> resulting request is also a new run of the mill http request not an >> ajax one and the options I set in the Request.HTML constructor are >> ignored: >> >> ... >> <form action='save' id='myform'> >> <input name='somefield' type='text'/> >> <input type='submit' id='sub'/> >> </form> >> ... >> <script text='javascript'> >> $('sub').addEvent('click',function(e){ >> new Event(e).stop(); >> req = new Request.HTML({method:'POST',url:'save'}) >> req.post($('ad-form')) >> } >> </script> >> >> the result from this is a non-ajax get request sent to the server and >> the response comes back obviously displaying the tiny ajax return >> value in full screen. >> >> why is this breaking? >> >> mootools version 1.2.3 >> > >
