[Javascript] Ajax question
Mike Dougherty
mdougherty at pbp.com
Sat Dec 30 17:04:59 CST 2006
On Sat, 30 Dec 2006 15:27:56 -0500
tedd <tedd at sperling.com> wrote:
> I see and have considered the timing difference. I should have said "I want to use ajax to send
>a variable and then refresh the current page, or a redirect to any other page."
>
> I don't want to use the form http://example.com/testpage.html?ajax=rock I have no problem
>receiving the variable I want so there's no need for me to include that variable in the url.
>
> I want to use ajax in the manner of:
>
> <a href="javascript:sndReq('rock');" >Rock </a>
>
> You see, I can send "rock" that way via ajax with no problems.
>
> What I can't do is via a single click refresh this page, or direct the browser to another page,
>via a href or whatever.
>
> I know this is hard to understand, but just simply consider this -- if the user clicks (The
>CLICK) this anchor --
>
> <a href="javascript:sndReq('rock');" >Rock </a>
>
> -- everything works. Now, how do I redirect the browser to another page from the same user click
>(The CLICK)?
I don't understand why you think you need ajax. If the page does a post submission back to the
old-school server-side form handler, you can set whatever session variables you want then refresh
the page.
Now if the idea is that you have a really archaic FrontPage-style website that you want to put
some kind of click tracking in, then you have a different problem. In the case of a bunch of
static .html files (no chance to do server-side form handling) then using ajax in an included
header (updating an existing site-wide include file) you can report behavior to your webservice
without needing to change the structure of the site.
So now I wonder what you do with <a href="javascript:sndReq('rock');">Rock</a> if there is no
javascript available? What about doing this:
<a href="a_valid_URL_to_go_to.php?what=rock" onclick="return sndReq('rock');">Rock</a>
If sndReq() returns false, the href will not be followed by the click - perhaps it could do
window.location=pagerefresh_whatever.html - or it could simply return true and allow the normal
function of the <a> tag to work. Arguably better would be:
<a id='Rock' href="a_valid_URL_to_go_to.php?what=rock" >Rock</a>
...then use some form of unobtrusive javascript to register the click event on the "Rock" object
to the sndReq() function given an argument of "Rock"
since you have a completely unusuable link given the href="javascript:whatever()" notation, it
seems that this use-case is not what I described above, so if you have control of the page(s) why
not eliminate ajax completely? Given that you want a page refresh after each change of state, you
might as well use well proven technologies the way they were meant to be used.
More information about the Javascript
mailing list