gpt4 book ai didi

javascript - JS 文件在 webhost 中不工作,但在我的本地 xampp 上工作

转载 作者:行者123 更新时间:2023-11-28 02:31:08 25 4
gpt4 key购买 nike

当我调用 index.js 时,它在我的虚拟主机服务器和 cdn 中也不起作用,但在我的本地 xampp 服务器上运行良好。

    <?php 
/* Main page with two forms: sign up and log in */
require 'db.php';
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Sign-Up/Login Form</title>
<?php include 'css/css.html'; ?>
</head>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($_POST['login'])) { //user logging in

require 'login.php';

}

elseif (isset($_POST['register'])) { //user registering

require 'register.php';

}
}
?>
<body>
<div class="form">

<ul class="tab-group">
<li class="tab"><a href="#signup">Sign Up</a></li>
<li class="tab active"><a href="#login">Log in</a></li>
</ul>

<div class="tab-content">

<div id="login">
<h1>Welcome to </h1>

<form action="index.php" method="post" autocomplete="off">

<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email" required autocomplete="off"
name="email"/>
</div>

<div class="field-wrap">
<label>
Password<span class="req">*</span>
</label>
<input type="password" required autocomplete="off"
name="password"/>
</div>

<p class="forgot"><a href="forgot.php">Forgot Password?</a></p>

<button class="button button-block" name="login" />Log
In</button>

</form>

</div>

<div id="signup">
<h1>Sign Up for Free</h1>

<form action="index.php" method="post" id="form1"
autocomplete="off">

<div class="top-row">
<div class="field-wrap">
<label>
First Name<span class="req">*</span>
</label>
<input type="text" required autocomplete="off"
name='firstname' id="txtNumeric" />
</div>

<div class="field-wrap">
<label>
Last Name<span class="req">*</span>
</label>
<input type="text"required autocomplete="off"
name='lastname'
id="txtNumeric" />
</div>
</div>


<div class="field-wrap">
<label>
Contact number<span class="req">*</span>
</label>
<input type="number"required autocomplete="off"
name='contact'
onclick="return AllowSingleSpaceNotInFirstAndLast();" />
</div>


<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email"required autocomplete="off" name='email'
onclick="return AllowSingleSpaceNotInFirstAndLast();" />
</div>

<div class="field-wrap">
<label>
Set A Password<span class="req">*</span>
</label>
<input type="password"required autocomplete="off"
name='password'/>
</div>

<button type="submit" class="button button-block"
name="register"
onclick="return validates()" />Register</button>

</form>

</div>

</div><!-- tab-content -->

</div> <!-- /form -->
<script

src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'>
</script>

<script src="js/index.js"></script>

<script type="text/javascript">

function validates(){

$(function() {

$('#txtNumeric').keydown(function (e) {

if (e.shiftKey || e.ctrlKey || e.altKey) {

e.preventDefault();

} else {

var key = e.keyCode;

if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key
<=
40) || (key >= 65 && key <= 90))) {

e.preventDefault();

}

}

});

});

function AllowSingleSpaceNotInFirstAndLast() {
var obj = document.getElementById('TextBox1');
obj.value = obj.value.replace(/^\s+|\s+$/g, "");
var CharArray = obj.value.split(" ");
if (CharArray.length > 2) {
alert("User name NOT VALID");
return false;
}[enter image description here][1]
else {
alert("User name VALID");
}
return true;
}

}

</script>

</body>
</html>

这里的问题是我无法在我的虚拟主机中正确运行代码。我的代码在本地 xampp 服务器上运行良好。我还编辑了数据库用户、数据库名称等,但没有帮助。谁能帮帮我?

谢谢!

附言。我是 stackoverflow 的新手。抱歉我的格式错误

最佳答案

我认为问题出在你的文件路径你应该检查你的文件路径或者可能是您没有在服务器上上传带有正确代码的所有文件。

替换这段代码

<script src="js/index.js"></script>

<script src="<?php echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>/js/index.js"></script>

关于javascript - JS 文件在 webhost 中不工作,但在我的本地 xampp 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50712756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com