jQuery ajax 不会发出 HTTPS 请求 [英] jQuery ajax won't make HTTPS requests

查看:32
本文介绍了jQuery ajax 不会发出 HTTPS 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网站上做一些非常基本的 jQuery ajax 内容,但遇到了很多麻烦.

I'm doing some pretty basic jQuery ajax stuff on my website, and I'm having a boatload of trouble.

相关代码如下:

$(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 发出的.

The page is loaded over HTTPS, but the XMLHttpRequests appear to go out over HTTP.

我什至尝试将 url 更改为绝对 url (https://larsendt.com/jsontest/randomdata),它仍然将请求发送到我网站的 HTTP 版本.

I've attempted even changing the url to the absolute url (https://larsendt.com/jsontest/randomdata), and it still sends the request to the HTTP version of my site.

自然,由于请求将发送到不同的协议,ajax 调用会失败(跨域等等).

Naturally, since the request is going to a different protocol, the ajax call fails (cross-domain and all that).

据 Chrome 报道:

As reported by 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 执行 301 重定向https://larsendt.com,但我看不出这会破坏什么(我相信这是相当标准的做法).

The only other relevant information I can think of is that I'm having nginx do a 301 redirect from http://larsendt.com to https://larsendt.com, but I don't see how that would break anything (I believe it's fairly standard practice).

如果您想要现场演示,损坏的版本仍在 https://larsendt.com/jsontest.

If you want a live demo, the broken version is still up at https://larsendt.com/jsontest.

无论如何,提前致谢.

推荐答案

尝试修复 URL,这样您的服务器就不必重定向

Try fixing the URL so your server doesn't have to redirect

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

这篇关于jQuery ajax 不会发出 HTTPS 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆