H_MZ 2016-03-04 23:04 采纳率: 0%
浏览 43

脚本无法通过https工作

This code works fine in the development machine and over http but when I change to https stops working Any help will be greatly appreciated

The code is from zippopotamus is use to get the city and state displayed in their respective input fields by first inserting the zipcode in its input field here I have a 2 div's that are hidden citybox statebox

when you insert the correct zip these boxes will show with the citybox and statebox

Edit The working code its now displayed here Thanks to all here and the suggestion provided by Anders Changing from http to https

$(document).ready( function()  {

  $("#citybox").hide();
  $("#statebox").hide();


  $('input#zip').bind("change keyup input",function() {
    var zip_in = $(this);
    var zip_box = $('#zipbox');

    if (zip_in.val().length<5)
    {

      zip_box.removeClass('has-error has-success');
    }
    else if ( zip_in.val().length>5)
    {

      zip_box.addClass('has-error').removeClass('has-success');
    }

    else if ((zip_in.val().length == 5) ) 
    {

      var urls =["https://api.zippopotam.us/us/" ,"https://api.zippopotam.us/pr/","https://api.zippopotam.us/vi/"];

      $.each(urls, function(i,u){ 
        $.ajax(u + zip_in.val(),{
          cache: false,
          dataType: 'json',
          type: 'GET',
          success: function(result, success) {
            // Make the city and state boxes visible

            $('#citybox').slideDown();
            $('#statebox').slideDown();

            // US Zip Code Records Officially Map to only 1 Primary Location for  abbreviation
            places = result['places'][0];
            $('#city').val(places['place name']);
            $('#state').val(places['state']);
            zip_box.addClass('has-success').removeClass('has-error');
          },
          error: function(result, success) {
            zip_box.removeClass('has-success').addClass('has-error');

          }
        });
      });
    }
  });
});
  • 写回答

3条回答 默认 最新

  • weixin_33695450 2016-03-04 23:14
    关注

    The problem is because you're reaching an insecure resource (http://api.zippopotam.us/us/) from a secure environment (your site running on https). This is not allowed. Your options are:

    • check if this server also runs on https;
    • write some back-end code to invoke this service, working like a proxy;
    • change to a vendor that supports https.
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助