我是Angular2
的新手。我正在嘗試將ID
值綁定到我的網址,但未綁定到網址。我使用的跨域和我的代碼如下:無法將ID值綁定到URL
onselect(id: number) {
let data = JSON.stringify(id);
let headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded'
});
let options = new RequestOptions({
headers: headers
});
var GetstateValue = this.http.post("http://localhost:34339/Home/GetStateById/?id", id, options)
GetstateValue.subscribe((res => this.Success(res)), res => this.Error(res));
console.log(GetstateValue, data);
}
當我硬編碼了自己的網址一樣http://localhost:34339/Home/GetStateById/1
則可以正常使用。
按瀏覽器的政策,CORS是不允許的。即時解決方案使用Chrome擴展[CORS EXTENSION](https://chrome.google.com/webstore/detail/cors-toggle/omcncfnpmcabckcddookmnajignpffnh?utm_source=chrome-ntp-icon)。或 - >設置(訪問控制 - 允許來源)在您的服務器 –
通過瀏覽器熱代碼工作正常? –
so..hot編碼的工作方式...檢查這是post方法或獲取方法 –