jQuery ajax不会发出HTTPS请求

weixin_38065414 2019-09-12 11:29:02
我在我的网站上做了一些非常基本的jQuery ajax东西,而且我遇到了一大堆麻烦. 这是相关的代码: $(document).ready( function() { $("#getdatabutton").click( function() { $.ajax({ url: "/jsontest/randomdata", type: "get", data: [{name:"ymax", value:$("#randomgraph").height()}, {name:"count", value:$("#countinput").val()}, {name:"t", value:Math.random()}], success: function(response, textStatus, jqXHR) { data = JSON.parse(response); updateGraph(data); $("#result").html(response); if(data["error"] == "") { $("#errorbox").html("None"); } else { $("#errorbox").html(data["error"]); } }, error: function(jqXHR, textStatus, errorThrown) { $("#errorbox").html(textStatus + " " + errorThrown); } }); }); }); 页面通过HTTPS加载,但XMLHttpRequests似乎通过HTTP传出. 我甚至尝试将url更改为绝对URL(https://larsendt.com/jsontest/randomdata),它仍然将请求发送到我的站点的HTTP版本. 当然,由于请求是针对不同的协议,因此ajax调用失败(跨域和所有这些). 据Chrome报道: The page at https://larsendt.com/jsontest/ displayed insecure content from http://larsendt.com/jsontest/randomdata/?ymax=500&count=32&t=0.08111811126582325. 我能想到的唯一其他相关信息是我有nginx从http://larsendt.com到https://larsendt.com进行301重定向,但我不知道这会如何破坏任何东西(我相信这是相当标准的做法). 如果你想要一个现场演示,破碎的版本仍然在https://larsendt.com/jsontest. 无论如何,提前谢谢.
...全文
496 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38073649 2019-09-12
  • 打赏
  • 举报
回复
尝试修复URL,以便您的服务器不必重定向 url: "/jsontest/randomdata/" // there was a missing trailing / // i.e. https://larsendt.com/jsontest/randomdata?ymax=500&count=32&t=0.9604179110508643 // was going to https://larsendt.com/jsontest/randomdata/?ymax=500&count=32&t=0.9604179110508643

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧