我加載網頁視圖內的本地HTML頁面中的IOS應用程序(使用Xamarin,但我不認爲它改變任何東西)IOS - 在WKWebView CORS從本地HTML文件
這本地的HTML頁面,使Ajax請求到遠程服務器。
一切工作正常,如果我使用UIWebView,但是當我嘗試使用WKWebView,而不是失敗。 它失敗,因爲CORS的,我試着用下面的HTML源代碼:
<html>
<body>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<h1>Test AJAX Requests</h1>
<br />
<button type="button" onclick="javascript: TestAjaxRequest('https://www.google.com');">Test AJAX Google</button>
<button type="button" onclick="javascript: TestAjaxRequest('https://api.github.com');">Test AJAX Github</button>
<br />
<p id="result"></p>
<script type="text/javascript">
function TestAjaxRequest(url) {
$.ajax({
url: url,
success: function (result) {
$("#result").html('Success');
},
error: function (jqXHR, exception) {
$("#result").html('An error occured: ' + jqXHR.responseText + exception);
},
});
}
</script>
</body>
</html>
到google.com調用失敗作爲CORS是不是該服務器上啓用,同時調用api.github.com工作,因爲CORS是在其服務器上啓用。
我不想在我的服務器上啓用CORS,我只想在WKWebView中啓用它,是否可以使其工作?