我有一個方法WCF,它返回一個JSON: enter image description hereAjax請求WCF服務得到錯誤Object對象
客戶端有一個腳本,應該把數據從WCF服務 腳本:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
$(document).ready(function() {
$('#btn').click(function() {
$.ajax({
url: 'http://192.168.200.100/Searching.BE.Service//WCFRESTService.svc/GetCategories',
method: 'get',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success:function(data)
{
alet(data.Announcing[0].Categories.id);
},
error: function (error)
{
alert(error);
}
})
var request = createCORSRequest("get", "http://192.168.200.100/Searching.BE.Service//WCFRESTService.svc/GetCategories");
request.send();
})
})
</script>
<input id="btn" type="button" />
點擊按鈕後,我有此錯誤:Object對象
和我有控制檯消息:
SCRIPT7002:XMLHttpRequest:網絡錯誤0x80070005,訪問被拒絕。
SEC7120:來源的http://本地主機:4945在頭訪問控制允許來源沒有找到..
如何解決這些問題呢?
您是否可以通過瀏覽器瀏覽器http:// 192.168.200.100/Searching.BE.Service // WCFRESTService.svc? – Mairaj
@MairajAhmad,這是因爲瀏覽器http://i.stack.imgur。 com/QlOis.png – Denisiva