JS程式碼如下:
在Chrome瀏覽器可以在console看到,如下的相關錯誤訊息
XMLHttpRequest cannot load http://localhost:49786/WebService1.asmx/HelloWorld2. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
所以必須在Web.Config加入下列的參數:
這樣可以接數到WebService回傳的資料了
參考
Error :Request header field Content-Type is not allowed by Access-Control-Allow-Headers
http://stackoverflow.com/questions/12409600/error-request-header-field-content-type-is-not-allowed-by-access-control-allow
沒有留言:
張貼留言