代码之家  ›  专栏  ›  技术社区  ›  Chris

ajaxjquery-为什么会有这个额外的斜杠?

  •  1
  • Chris  · 技术社区  · 16 年前

    我经常看到与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
          }
       });
    

    谢谢

    1 回复  |  直到 16 年前
        1
  •  8
  •   Kobi    16 年前

    它在链接或图像中指向站点的根,就像其他url一样。
    例如,如果你在 http://example.com/sub/site.html , somefile.php http://example.com/sub/somefile.php /somefile.php http://example.com/somefile.php