使用HTTP而不是HTTPS的AJAX [英] AJAX using HTTP instead of HTTPS

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

问题描述

我的AJAX请求正在使用HTTP,即使该请求源自使用HTTPS的页面.知道为什么要降级为HTTP吗?

My AJAX request is using HTTP even though the request is originating from a page using HTTPS. Any idea why it's downgrading to HTTP?

这是我的AJAX请求:

Here's my AJAX request:

$(function() {

  // Update section options whne course is changed
  $('#id_new_course').change(function() {

    // Get selected coursenum
    var val = $(this).val();
    var sect_input = $('#id_section');

    // Disable #id_section when no course is selected
    if (val == '') {
      sect_input.empty();
      sect_input.prop('disabled', true);
    } else {
      // Get list of sections for selected course and update #id_section options
      $.ajax({
        url: '/account/support_dashboard.get_course_sections/' + val + '/',
        dataType: 'json',
        success: function(data) {
          // Empty options and add new ones to #id_section
          sect_input.empty();
          $.each(data, function(value, key) {
            sect_input.append($('<option></option>').attr('value', value).text(key));
          });
          sect_input.prop('disabled', false);
        },
        error: function() {
          console.log('ERROR OCCURRED TRY AGAIN');
        }
      });//ajax
    }//if

  });

}); //ready

这是我的网络控制台中的错误输出:

Here's the error output in my web console:

Mixed Content: The page at 'https://www.myeducator.com/account/support_dashboard/1027/993532704604577793/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.myeducator.com/account/support_dashboard.get_course_sections/915ba/'. This request has been blocked; the content must be served over HTTPS.

正在通过HTTPS加载javascript文件:

The javascript file is being loaded over HTTPS:

此外,实际的ajax请求以HTTPS发出:

Also, the actual ajax request is going out as HTTPS:

我也认为这与我的Web服务器(nginx)没有任何关系.我只有一个重写命令,可以使用相同的请求方案将所有未处理的子域重定向到www.myeducator.com:

I also don't think it has anything to do with my web server (nginx). I only have a single rewrite command that redirects any unhandled subdomains to www.myeducator.com using the same request scheme:

server {
  listen 443 default_server ssl;
  server_name _;

  ...

  # the rewrite string
  rewrite ^ $scheme://www.myeducator.com$request_uri redirect;
}

推荐答案

我有一个类似的问题,非常令人困惑...

I had a similar problem, very puzzling...

Mixed Content: The page at 'https://domain.com/blah.json' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://domain.com'. This request has been blocked; the content must be served over HTTPS.

结果是在IIS上的MIME类型中未设置.json.添加.json扩展名后,一切都会正常进行.

It turned out to be .json was not setup in the MIME types on IIS. Once .json extension was added everything worked as it should.

我怀疑是您的端点"dashboard.get_course_sections"带有一个点,这使您的服务器认为这是获取它不支持的资源.

My suspicion would be your endpoint "dashboard.get_course_sections" has a dot which makes your server think it's a resource to grab that it doesn't support.

这篇关于使用HTTP而不是HTTPS的AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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