I have also run into this problem. Using the href/action works great for links and forms but isn't always applicable since some ajax calls don't rely on those html items. What I do is set a dummy meta tag with the url in it and pull that in with javascript. Not the best solution but at least I can keep my javascript completely seperate...
I have discussed this before: http://groups.google.ca/group/symfony-users/browse_thread/thread/50389a8ad4d987c/d983f5b09c512702?lnk=gst&q=ajax+url#d983f5b09c512702 The ideal soltion would be to use the html5 data attribute: http://ejohn.org/blog/html-5-data-attributes/ but using this breaks xhtml validation... - Kevin On Aug 9, 1:16 am, "Sebastien Armand [Pink]" <khe...@gmail.com> wrote: > In both your suggestions, if I get them correctly, the idea is that from a > template, I should output some javascript to set some variables or any other > way to get the url back from my javascript later. Which seems weird to me, > and "wrong" on the side that I don't really want to add js in my templates > and prefer to keep it separate. > > For an idea, my case goes like this: I have a form to enter some information > of a sofa for example, and one of the fields allows me to chose a "design" > for the sofa. This design has some default dimensions: width and length. > Those are the information I want to bring back through ajax. > > So: > 1. get to the form page to create a new sofa > 2. choose a design > 3. this triggers the JS to go look for the default size (from the design > module) and fill it in the form. > > my js file is in the js folder and in it I have a url linking to > "/design/:design_id.json" but for this to work on my dev environment, I need > that url to be: "/frontend_dev.php/design/:design_id.json". > > So is there a way to output that url in the js through php and symfony? > Or a way that I can get it through the dom but without already having to put > it here by myself beforehand? > > 2010/8/7 Stéphane <stephane.er...@gmail.com> > > > It shouldnt break. > > You should do this: > > > Create a route to reach your module/action (/apps/$app/config/routing.yml, > > check doc). > > Then in a template, write something like: > > > <script type="text/javascript"> > > window.myactionurl = "<?php echo url_for('@my_route')?>"; > > > alert(window.myactionurl); > > $.post(window.myactionurl, null, function(data){//...}); > > </script> > > > This is a stupid example (about the window.myactionurl, store this > > somewhere else). > > > Before Printing, Think about Your Environmental Responsibility! > > Avant d'Imprimer, Pensez à Votre Responsabilitée Environnementale! > > > On Sat, Aug 7, 2010 at 12:25 PM, Phennim <phen...@gmail.com> wrote: > > >> Get the url from the DOM using js. > > >> $('a.do-ajax').click(function(){ > >> var url = $(this).attr('href'); > > >> $.post(url, function(data){ > >> //do stuff > >> }); > >> }); > > >> On Aug 7, 11:11 am, "Sebastien Armand [Pink]" <khe...@gmail.com> > >> wrote: > >> > Hello everyone, > > >> > I was wondering how to get an environment independent url in javascript > >> > files. My js needs to connect to the server and get some JSON data and > >> > update a form on certain actions. But putting that actions url in the js > >> > directly breaks everything when you change environment... > > >> > I might be missing something here but don't see the light of how to do > >> it, > >> > any insight welcome ;-) > > >> -- > >> If you want to report a vulnerability issue on symfony, please send it to > >> security at symfony-project.com > > >> You received this message because you are subscribed to the Google > >> Groups "symfony users" group. > >> To post to this group, send email to symfony-users@googlegroups.com > >> To unsubscribe from this group, send email to > >> symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com> > >> For more options, visit this group at > >>http://groups.google.com/group/symfony-users?hl=en > > > -- > > If you want to report a vulnerability issue on symfony, please send it to > > security at symfony-project.com > > > You received this message because you are subscribed to the Google > > Groups "symfony users" group. > > To post to this group, send email to symfony-users@googlegroups.com > > To unsubscribe from this group, send email to > > symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com> > > For more options, visit this group at > >http://groups.google.com/group/symfony-users?hl=en -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en