gpt4 book ai didi

html - 绕过跨域限制 ajax - jquery 和/或 iOS

转载 作者:可可西里 更新时间:2023-11-01 13:37:00 24 4
gpt4 key购买 nike

我有一个通过 UIWebView 加载本地 HTML 的 iOS 应用程序。 HTML 通过 AJAX 连接到 jquery。对于 HTML,我有一个内容文件夹和一个容器文件夹。 Content 文件夹有很多 html 文件,container 文件夹有一个 html 文件,可以按特定顺序打开 container 文件夹中较小的 html。问题是由于 AJAX 中的跨域限制,容器 HTML 不会从容器文件夹加载任何内容。有什么我可以通过 Xcode 添加的东西可以让我绕过限制,或者我可以添加 HTML/Jquery 的任何东西可以让我绕过它吗?提前致谢!

         //ReplaceDIV
function loadInDiv(source)
{
// alert('start');
$.ajax({
url: source,
async: false,
crossDomain: true,
success: function(data) {$('#content').append(data);},
});
// $.get(source, function(data) {
// alert(data);
// $('#contents').append(data);
// });
// $(destination).load(source);
}

最佳答案

删除:

跨域:true,

你应该准备好了。

编辑:

据我了解,手头的任务是使用 ajax 将一个 html 文件的内容加载到同一服务器上的另一个文件。当这在 UIWebView 中从本地资源完成时,这将是一个 localhost 请求。来自 [JQuery 文档:

If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain.

在本地主机请求上,强制跨域请求会破坏请求,导致它不加载任何内容。另外,作为旁注,跨域请求与您设置的同步请求不兼容:

异步:错误,

关于html - 绕过跨域限制 ajax - jquery 和/或 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com