[英]API is not working in IE11 by using AJAX, .html page
$.support.cors = true;
$.ajax({
type: "GET",
url: "https://jsonplaceholder.typicode.com/todos/1",
contentType: "application/json",
datatype: "json",
crossDomain: true,
success: function (data) {
debugger
if (data) {
console.log('true');
}
else {
console.log('false');
}
},
error: function (status, err) {
debugger
console.log(status);
}
});
當我調用 API 時,ajax 調用不成功,但會引發錯誤。 請給我一個解決方案。
你 API 支持 cors 嗎? 如果不是,您需要安裝 package 和 API,然后需要在啟動 class 中進行設置。
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
}
}
1-檢查您是否在某處使用以下標簽?
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
如果是,只需刪除它,它將成為您問題的解決方案。
2- You are accessing https://jsonplaceholder.typicode.com which is a secure https URL, what URL is trying to access it. 確保此 URL 應為 https。 例如: https://localhost:8000
我認為debugger
關鍵字會導致問題,否則它可以正常工作。
$.support.cors = true; $.ajax({ type: "GET", url: "https://jsonplaceholder.typicode.com/todos/1", contentType: "application/json", datatype: "json", crossDomain: true, success: function(data) { if (data) { console.log('true'); } else { console.log('false'); } }, error: function(status, err) { console.log(status); } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.