0

I have a script that switches background image on hover:

$('div#example').hover(function(){
  $(this).css('background',"url('images/bg_2.png') no-repeat bottom");
});

I am using a WAMP development environment, and this works fine if the url I use is either:

localhost/example/web -or- localhost/example/web/frontend_dev.php

However, if I use localhost/example/web/frontend_dev.php/, (added slash at end) the image no longer loads? What is going on?

Thanks.

Additional info:

  • For the 'effected' case-scenario, all images set through CSS work fine (only images referenced through JS have problems). Favicon Does NOT load either, for some reason.
  • localhost/web/ works fine
whamsicore
  • 8,320
  • 9
  • 40
  • 50

2 Answers2

0

What happens if you put a slah before the images folder, such as:

/images/bg_2.png

It wont when you're on the URL: localhost/example/web/frontend_dev.php/

As it'll be looking for the path: localhost/example/web/frontend_dev.php/images, which is wrong as I'm guessing your images are in localhost/example/web/images

sipher_z
  • 1,221
  • 7
  • 25
  • 48
0

Based on the url's you are providing (localhost/example/web, localhost/example/web/frontend_dev.php, etc) it seems you are not using a Virtual Hosts setup as described in here http://www.symfony-project.org/gentle-introduction/1_4/en/03-Running-Symfony (see 'Web Server Configuration' section)

You will then be able to reference the image using /images/bg_2.png

There are a number of other reasons why you should use a Virtual Host setup including security (only files in web/ need to be web accessible) and ease of deployment (ie, using urls like localhost/example/web wont work when deployed to another server unless you mimic your local setup exactly)

d.syph.3r
  • 2,215
  • 1
  • 19
  • 14
  • I remember trying to set that up correctly, however it is very confusing to me. What does: "Now it is time to change your Apache configuration, to make the new project accessible to the world." mean anyways? Also, is altering the httpd.conf file and the etc/host file 2 mutually exclusive options, or are they done in parallel? Thanks for your input. – whamsicore Apr 20 '11 at 22:20
  • You have to alter the httpd.conf, this will allow you to access your website via something like [http://localhost:8000/](http://localhost:8000/). If you would like to use a custom domain name, you need to also edit the hosts file at /etc/hosts. This will allow you to access your website via something like [http://mywebsite.dev/](http://mywebsite.dev/). If you follow through the above linked guide step by step you should have no problem setting this up. – d.syph.3r Apr 21 '11 at 08:18
  • I still don't know why the '/' is causing troubles, but this answer this response made the most sense. – whamsicore Apr 22 '11 at 03:16