2009-10-17 62 views
1

我經常看到那裏的AJAX文件正在聯繫碼(somefile.php在下面的例子中)是前面帶有/ajax jquery - 爲什麼這個額外的斜線?

這是/只是爲了保持結構www.example.com/somefile.php或者是像逃避安全方面的原因?如果是後者,解釋也將有所幫助。

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

謝謝。

回答

8

它指向網站的根,就像鏈接或圖像中的其他網址一樣。
例如,如果你在http://example.com/sub/site.htmlsomefile.phphttp://example.com/sub/somefile.php,而/somefile.phphttp://example.com/somefile.php

相關問題