ajax jquery - 为什么这个额外的斜线?

Chr*_*ris 1 ajax jquery

我经常看到代码,其中联系的ajax文件(somefile.php在下面的示例中)前面有一个/

/只是为了保留结构www.example.com/somefile.php还是出于安全原因而逃避?如果是后者,解释也会有所帮助..

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

谢谢.

Kob*_*obi 8

它指向网站的根,就像链接或图像中的每个其他网址一样.
例如,如果你在http://example.com/sub/site.html,somefile.phphttp://example.com/sub/somefile.php,而 /somefile.php进入http://example.com/somefile.php