加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

jQuery ajax不会发出HTTPS请求

发布时间:2020-12-13 21:06:50 所属栏目:Nginx 来源:网络整理
导读:我在我的网站上做了一些非常基本的jQuery ajax东西,而且我遇到了一大堆麻烦. 这是相关的代码: $(document).ready( function() { $("#getdatabutton").click( function() { $.ajax({ url: "/jsontest/randomdata",type: "get",data: [{name:"ymax",value:$("

我在我的网站上做了一些非常基本的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,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.

无论如何,提前谢谢.

尝试修复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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读