代码可以在 XAMPP 服务器中 运行 但不能在 000webhost.com 中 运行

Code can run in XAMPP server but cannot run in 000webhost.com

function valform()
{
 var name = document.getElementById("username").value;
 var h2 = document.getElementById("height1").value;
 var w2 = document.getElementById("weight1").value;
 var r2 = document.getElementById("txtresult").value;
 
 if( name == ""  || h2 == "" || w2 == "" || r2 == "" )
 {
  alert("Please fill in the blank(s) first");
  return false;
 }
 if(!($('input[type=radio]:checked').size() == 12))
 {
  alert("You must answer all the questions");
  return false;
 }
}

所以,上面的代码基本上不能在 000webhost.com 中 运行 但可以 运行 与 XAMPP 服务器。如果我在所有单选按钮都未选中时单击提交,它应该显示警报但它只是转到另一个页面。我检查了所有语法是否正确,但仍然无法正常工作。所以我想知道为什么? link: https://cancertool123.000webhostapp.com/Questionnaire%20(Colon%20Cancer).php

一些解释会有所帮助。

改变

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

正如您在控制台中看到的(在您的网站中按 F12),出现错误:

Mixed Content: The page at 'https://cancertool123.000webhostapp.com/Questionnaire%20(Colon%20Cancer).php' was loaded over HTTPS, but requested an insecure script 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'. This request has been blocked; the content must be served over HTTPS.

问题是您正在 https 站点中加载 http 文件。

您正在从 http 加载 jquery 文件,并且您的网站正在 https 上运行,因此将其更改为此

https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js

它会起作用