且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery.ajax请求和jsonp进行基本身份验证

更新时间:2023-11-30 23:50:46

短版本是你不能这样做的。您的怀疑是正确的,因为您是本地的,这些文件是远程的,您无法访问它们,您被同源政策。解决方法是 JSONP ,但这似乎并不适用于你的情况......

The short version is you can't do this. Your suspicions are correct, because you're local and these files are remote, you can't access them, you're being blocked by the same-origin policy. The work-around for that is JSONP, but that really doesn't seem to apply to your situation...

JSONP的工作方式不同,它是通过< script> 标签包含的GET请求获取文件,因此您不会发送特殊标题或任何内容。

JSONP works differently, it's a GET request via a <script> tag include to get the file, so you're not sending special headers or anything.

您需要通过您所在的服务器代理请求(域名所在此脚本正在运行)或其他代理选项,但是从客户端到另一个域的访问被阻止,主要是出于安全原因。

You'll need to proxy the request through the server you're on (the domain of where this script is running) or another proxy option, but going from the client to another domain is blocked, mainly for security reasons.