jQuery的AJAX不会让HTTPS请求 [英] jQuery ajax won't make HTTPS requests

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

问题描述

我正在做一些pretty的基本jQuery的AJAX的东西在我的网站,和我有麻烦勿庸置疑。

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

下面是相关的code:

Here's the relevant code:

$(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,但XMLHtt prequests似乎要通过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.

不管怎样,在此先感谢。

Anyway, thanks in advance.

推荐答案

尝试固定的网址,这样你的服务器没有重定向

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天全站免登陆