If.request.xhr?

Hope I’m not to far off base here -
I want a link that will first go the controller, test for javascript and
then re-direct to either ajax or non-ajax page.
I have the controller code set up but a bit unsure about the link itself

Do I need to use a link_to_remote link to get the user over to the
controller /action and if.request.xhr?
or should just a link_to work.
I ask because a link_to doesn’t seem to mean anything , js is turned on
and
still wind up at the non-ajax form.

Stuart

Hi,

If your using the normal link_to helper, your link wont use a
xmlhttprequest-object to send the request, but a normal get/post
request. Link_to_remote uses the prototype javascript library to send
an ajax-request and you will be able to recognize the request as ajax
in your controller.

Richard

On 10/17/06, [email protected] [email protected]
wrote:

Richard
Okay, that’s what I thought. However , the link isn’t working , meaning
right now when I place the mouse over the link it says /mydomain/#

I have this in the html doc:

<%= javascript_include_tag "prototype" %>

And have composed the link as such (though I’ve tried a few different
variations)
<%= link_to_remote ‘Search’, {:url => { :action => ‘failover’ }} %>

Shouldn’t that create the link ?

Thank you
Stuart

Dark A. <sambient@…> writes:

Okay, that’s what I thought. However , the link isn’t working , meaning
right now when I place the mouse over the link it says /mydomain/#

That’s because the link is called with Javascript and coded into a JS
function
call, whereas the status bar only shows the value of the link’s href
attribute.
View Source and you’ll see an onclick which actually calls the remote
call.

The itself never actually gets activated, it’s disabled by the
javascript in
the
s onclick.

If you want, you can supply a URL to be called if people have javascript
switched off, by adding an :href to the link_to_remote:

<%= link_to_remote “Text”, {:controller => blah, :action => blah},
{:href =>
url_for(:controller => blah2, :action => blah3)}

This will allow non-javascript users to access your site and possibly
get the
information they would have gotten, at the cost of a full page request.
That’s
not an automatic thing thought, your code has to be able to deal with
both
requests

Gareth

Bump :slight_smile:

On 10/17/06, Dark A. [email protected] wrote:

an ajax-request and you will be able to recognize the request as ajax
<%= javascript_include_tag “prototype” %>

And have composed the link as such (though I’ve tried a few different
variations)
<%= link_to_remote ‘Search’, {:url => { :action => ‘failover’ }} %>

Shouldn’t that create the link ?

Maybe I’m way off base here. I am looking at a codecite presentation.
I’ve set up my controller action as such:

def failover
if request.xhr?
redirect_to :controller => ‘ajaxsearch’, :action => ‘index’
else
redirect_to :controller => ‘searches’, :action => ‘new’

On 10/17/06, Dark A. [email protected] wrote:

right now when I place the mouse over the link it says /mydomain/#
the s onclick.
information they would have gotten, at the cost of a full page request.
<%= link_to_remote “Search for jobs”, {:controller => ‘ajaxsearch’,

Am I totally lame and missing something or is something weird going on ?

Stuart

Alright, I think I got it now , I added the needed div / dom id. Which
updated the page the link is on. I guess that is the way it’s intended
to
work.

Stuart


Dark A. <sambient@…> writes:

Alright, I think I got it now , I added the needed div / dom id. Which updated
the page the link is on. I guess that is the way it’s intended to work.

Stuart

That’ll be my bad, for trying to guess the link_to_remote function call.
Well
done for working it out

On 10/17/06, Gareth A. [email protected] wrote:

attribute.
<%= link_to_remote “Text”, {:controller => blah, :action => blah}, {:href
Gareth
Thanks Gareth. Unfortunately then something is going wrong here.
I created the link_to_remote -
<%= link_to_remote “Search for jobs”, {:controller => ‘ajaxsearch’,
:action
=> ‘search’}, {:href =>
url_for(:controller => ‘searches’, :action => ‘new’)}%>

I believe that is right. With javascript turned on the link does
nothing.
With js off, I get taken to the right place.

Page source :
Search for jobs

Am I totally lame and missing something or is something weird going on ?

Stuart