简体   繁体   English

国际电话号码的jQuery插件:标志和电话占位符丢失

[英]jQuery plugin for international phone numbers: flags and phone placeholder missing

I'm using intl-tel-input , jQuery plugin for international phone numbers, for one of my projects. 对于我的一个项目,我正在使用国际电话号码的intl-tel-input ,jQuery插件。 The plugin claims to "Automatically set the input placeholder to an example number for the selected country", but I can't get that to work properly. 该插件声称“自动将输入占位符设置为所选国家/地区的示例编号”,但我无法使其正常工作。 So far I tried 2 things: 到目前为止,我尝试了两件事:

1) I downloaded the library and referenced one of its JS files from my code ( similar to the demo ). 1)我下载了库并从我的代码中引用了一个JS文件(类似于demo )。 Here's a snippet of my JS file: 这是我的JS文件的片段:

  $("#phone").intlTelInput({
    allowExtensions: false,
    autoFormat: true,
    autoHideDialCode: false,
    autoPlaceholder: true,
    defaultCountry: "ng",
    ipinfoToken: "yolo",
    nationalMode: true,
    numberType: "MOBILE",
    onlyCountries: ['ng', 'us', 'gb'],
    preferredCountries: [],
    utilsScript: "/projects/intl-tel-input-master/lib/libphonenumber/build/utils.js" 
  });

but I got the following error in the JS console of Chrome: 但我在Chrome的JS控制台中遇到以下错误:

XMLHttpRequest cannot load file:///projects/intl-tel-input-master/lib/libphonenumber/build/utils.js. XMLHttpRequest无法加载file:///projects/intl-tel-input-master/lib/libphonenumber/build/utils.js。 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. 交叉源请求仅支持协议方案:http,data,chrome,chrome-extension,https,chrome-extension-resource。

2) I put the library folder on a server and referenced utils.js file with server url ( http://web.mit.edu/aizhan/www/intl-tel-input-master/lib/libphonenumber/build/utils.js ). 2)我将库文件夹放在服务器上,并使用服务器URL引用utils.js文件( http://web.mit.edu/aizhan/www/intl-tel-input-master/lib/libphonenumber/build/utils。 js )。 This still doesn't work on my machine, but it works in codepen with HTTP protocol but not with HTPPS: 这仍然无法在我的机器上运行,但它可以在带有HTTP协议的codepen中运行,但不适用于HTPPS:

HTTP: http://codepen.io/atoregozh/pen/raEPbv HTTP: http//codepen.io/atoregozh/pen/raEPbv
HTTPS: https://codepen.io/atoregozh/pen/MYMLXv HTTPS: https//codepen.io/atoregozh/pen/MYMLXv

My overall question: how could I make the library work locally? 我的整体问题:如何让图书馆在本地运作? I also have 2 subquestions: 1) How to fix the error about XMLHttpRequest loading? 我还有2个子问题:1)如何修复关于XMLHttpRequest加载的错误? (I read about it before from other posts on stackoverflow and I don't want to mess with the security settings); (我之前从stackoverflow上的其他帖子中读过它,我不想搞乱安全设置); 2) Why the code works through HTTP but not through HTTPS? 2)为什么代码通过HTTP而不是通过HTTPS工作?

I would really appreciate your help. 我将衷心感谢您的帮助。 If you want to see the actual project code, the index.html file is here and Javascript file is here 如果你想看到实际的项目代码, index.html文件就在这里Javascript文件就在这里

question :how could I make the library work locally? 问题 :如何让图书馆在本地工作?

you use in Yeoman , ExpressJs or IIS Express. 你在Yeoman ,ExpressJs或IIS Express中使用。

eg(run server): yeoman server 例如(运行服务器):yeoman服务器

I'm test by IIS Express , demo file is right. 我是通过IIS Express测试的,演示文件是对的。

question :How to fix the error about XMLHttpRequest loading? 问题 :如何解决有关XMLHttpRequest加载的错误?

you load resource in another server (cross domain ), I prefer load proxy in curent server. 你在另一台服务器(跨域)加载资源,我更喜欢在curent服务器中加载代理。 To resolve this problem, refer to 'Loading cross domain html page with jQuery AJAX' . 要解决此问题,请参阅“使用jQuery AJAX加载跨域html页面”

another question :Why the code works through HTTP but not through HTTPS? 另一个问题 :为什么代码通过HTTP而不是通过HTTPS工作?

if you see the browser console , including the code below. 如果你看到浏览器控制台,包括下面的代码。

Loading mixed (insecure) display content "" on a secure page.
Blocked loading mixed active content "http://web.mit.edu/aizhan/www/intl-tel-input-master/build/js/intlTelInput.js"

resolve your problem in firefox link 在firefox 链接中解决您的问题

if an HTTPS page includes HTTP content, the HTTP portion can be read or modified by attackers, even though the main page is served over HTTPS. 如果HTTPS页面包含HTTP内容,则攻击者可以读取或修改HTTP部分,即使主页面是通过HTTPS提供的。

good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM