tags:

views:

103

answers:

1

I often see code where the ajax files being contacted (somefile.php in the example below) are preceded with a /

Is this / just to preserve the structure www.example.com/somefile.php or is it for security reasons like escaping? If it's the latter, an explanation would also help..

$.post('/somefile.php', { id: id, val: val }, function(data) {
      if (something) {
         do something
      } else {
         do something else
      }
   });

Thanks.

+8  A: 

It points to the root of the site, just like every other url, in links or images.
For example, if you're on http://example.com/sub/site.html, somefile.php goes to http://example.com/sub/somefile.php, while /somefile.php goes to http://example.com/somefile.php

Kobi