2017-03-23 73 views
0

這是我在sign-up.tsHTTP POST請求從離子2個前PHP服務器端

let link = "http://localhost/signup.php"; 
    this.http.post(link, signupdata) 
     .subscribe(data => { 
     console.log("Success"); 
     },error => { 
     console.log("Error"); 
     }); 

代碼時,我提出我碰到下面的錯誤在我的控制檯形式

XMLHttpRequest cannot load http://localhost/signup.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. 

幫幫我在解決這個問題。

+0

的可能的複製[「否‘訪問控制允許來源’標頭出現在所請求的資源」(HTTP: //www.stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Alex

回答

0

把這些行加入到您signup.php腳本頂部:

header('Access-Control-Allow-Origin: *'); 
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE'); 
header('Access-Control-Allow-Credentials: true'); 
+0

謝謝。這就像一個魅力:) –

+0

偉大 - 高興地幫助。不要忘記投票我的答案;-) – Chris