On Dec 24, 4:42 pm, weheh <[email protected]> wrote:
> I guess that must be it. I am always using href="#" on my links with
> ajax onclicks, so it never redirects even if return false; is missing.
>
> On Dec 24, 4:40 pm, Marin Pranjic <[email protected]> wrote:
>
> > ok, i made a mistake. just ignore the explanation. didn't test :D
> > just try experimenting and see what happens.
> > return false --> prevents reloading, just like massimo said.
> > if you call function by onclick event in <a> with a href set, return will
> > prevent hyperlink event.
> > you can set href="#" and that will have the same effect as return false.
> > but i prefer return false
>
> > On Fri, Dec 24, 2010 at 10:26 PM, Marin Pranjic
> > <[email protected]>wrote:
>
> > > try this:
> > > <html>
> > > <head>
> > > <script>
> > > function remove()
> > > {
> > > var a = document.getElementById('id');
> > > var b = (a.parentNode).removeChild(a);
> > > }
> > > function add(x,y){
> > > alert(x+y);
> > > return x+y;
> > > }
> > > </script>
> > > </head>
> > > <body>
> > > <span id="id">text</span>
> > > <br />
> > > <input type="button" value="Remove text" onclick="remove();" />
> > > <a href="" onclick="add(2,3); return false;">2+3?</a>
> > > </body>
> > > </html>
>
> > > now try removing "return false" after add function.
> > > the thing is, if function returnes value, page will be reloaded.
> > > If functions does not have a return value, it will not reload the page.
> > > But using "return false" always won't hurt ;)
>
> > > p.s. you can see if it is reloaded if you remove text and click 2+3?.
> > > if text is back, it is reloaded.
>
> > > On Fri, Dec 24, 2010 at 9:52 PM, weheh <[email protected]> wrote:
>
> > >> I use onclick="ajax(...);" in lots of places without the return false
> > >> and never have observed the page getting reloaded on either firefox or
> > >> chrome.
>
> > >> On Dec 24, 1:37 pm, mdipierro <[email protected]> wrote:
> > >> > only
>
> > >> > <a onclick=".....; return false;">...</a>
>
> > >> > else the page is reloaded no matter what the ..... do.
>
> > >> > On Dec 24, 11:26 am, weheh <[email protected]> wrote:
>
> > >> > > Should one's view *always* have a return false; statement immediately
> > >> > > after an ajax request? Why?
>
>