AJAX using HTTP instead of HTTPS

2020-06-18 10:11发布

问题:

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?

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.

The javascript file is being loaded over HTTPS:

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

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;
}

回答1:

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.

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.

Edit: 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.