> I have a Rails app (3.0.3) that uses jQuery (1.4.4) to do some AJAX
> requests. For example, when doing a AJAX request on a page like
> "http://localhost:3000/users/3"; with
> $("div#profile_box").load("profile");
> the browser always tries to fetch from "http://localhost:3000/users/
> profile". It simply ignores the "3".
> But when adding a trailing slash after the 3 then it uses"http://
> localhost:3000/users/3/profile".
> Why does it not work without the trailing slash? I reproduced this

Pretend it's a file system...  You are in the "users" directory.  In that 
directory is a file called "3" and now you are asking for "profile".  Without 
any slashes, it's going to assume that you want the file "profile" in the 
current directory which is "users" so you get "users/3".

It's more complicated than a file system though since you can't ensure a 
trailing slash.  I might remove it.  Apache might be configured to get rid of 
it, etc.

You can't prefix "profile" with a slash since that would pull up 
http://localhost/profile.

I think you're only option is to tweak the load() call...  to pull in the value 
of document.location.href and append "profile" with a possible slash to 
separate them if it doesn't already exist.  I don't know if jQuery/javascript 
has anything to make that simpler.

You might also be able to set the BASE HREF html tag, but that will most likely 
screw up all your image paths, etc...

-philip

> under Chrome and Firefox (not tried any other browser). And this seems
> to be indeed a client side problem (I watch the request on the browser
> console).
> I know, this is not very Rails specific, but I already posted the
> problem in the jQuery forum without receiving any explanation yet. And
> I know there are a lot of Rails people using jQuery, so the above
> scenario is nothing special.
> How do you provide the URL to the jQuery AJAX functions? Do you have
> the same problem? (I reproduced it also under another system.).
> 
> Regards,
> Kai
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to