2015-10-01 41 views

回答

0

網址101:如果你在一個網站「http://example.com/subdir」,那麼這裏的各種URL類型是如何被intrepreted:

relative:    foo.html     -> http://example/subdir/foo.html 
relative:    ../foo.html     -> http://example.com/foo.html 
relative:    ../otherdir/foo.html  -> http://example.com/otherdir/foo.html 
local absolute:  /foo.html     -> http://examle.com/foo.html 
local relative:  google.com/hi/mom/foo.html -> http://example.com/subdir/hi/mom/foo.html 
local absolute:  /google.com/hi/mom/foo.html -> http://example.com/google.com/hi/mom/foo.html 
universal absolute: http://google.com/kittens -> http://google.com/kittens 

換句話說,如果你想解釋的URL作爲其他方面,它必須是「通用絕對」,幷包含完整的網址:protocol://host/path

+0

謝謝,它工作:)但現在我得到不允許錯誤:XMLHttpRequest無法加載http://localhost/handler.php。請求的資源上沒有「Access-Control-Allow-Origin」標題。 Origin'http://example.com'因此不被允許訪問。你對這個問題有什麼想法嗎?我如何解決它? –

+0

你不能對「外部」地址執行ajax請求,除非你設置了CORS頭,正如錯誤所述。 –

+0

我該如何實現它以下面的代碼:var xmlhttp = new XMLHttpRequest(); xmlhttp.open(「POST」,「http://localhost/handler.php」); xmlhttp.setRequestHeader(「Content-Type」,「application/json; charset = UTF-8」); xmlhttp.send(json_data); –

相關問題