javascript - 在 Cpanel 上使用 Javascript AJAX POST 时出现 500 内部服务器错误

标签 javascript php jquery ajax cpanel

<分区>

尝试在我的网页上注册用户时出现以下错误:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

^ 指向带有注册脚本的 PHP 文件

并且指向以下脚本的内部服务器错误:

 $("#login-submit").on('click', function () {
    $.ajax({
      url: 'ext/login_process.php',
      type: "POST",
      data: $("#login-form").serialize(),
      success: function (result) {
        if (result === "done") {
          window.location.href = "index.php";
        } else {
          var elementExists = document.getElementById("msg-default");
          if (elementExists !== null) {
            document.getElementById("msg-default").innerHTML = "";
          }
          document.getElementById("err-msg").innerHTML = "<div class = 'alert alert-danger text-uppercase'><strong>Error!&nbsp;</strong>" + result + "</div></div>";
        }

      },
      error: function (xhr, resp, text) {
        console.log(xhr, resp, text);
      }
    });

  });

错误发生在按下注册按钮时。如果用户名已被使用,它会正常工作,然后该消息将按应有的方式显示。

HTML:

<form name="register-form" id="register-form" method="POST">
                        <h5 class="text-center">Register</h5>
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Username" name="username" required>
                        </div>
                        <div class="form-group">
                            <input type="password" class="form-control" placeholder="Password" name="password" required>
                        </div>
                        <div class="form-group">
                            <input type="password" class="form-control" placeholder="Repeat password" name="c-password" required>
                        </div>
                        <div class="form-group">
                            <label>I am...</label>
                            <div class="radio">
                                <label><input type="radio" name="position" checked value="s">&nbsp;Student</label>
                            </div>
                            <div class="radio">
                                <label><input type="radio" name="position" value="t">&nbsp;Teacher</label>
                            </div>
                        </div>
                        <div class="err-msg" id="err-msg"></div>
                    </form>
                    <button id="register-submit" class="btn btn-success">Senda</button>

PHP:

$username = trim(preg_replace('/\s+/', ' ', htmlspecialchars($_POST["username"])));
$password = htmlspecialchars($_POST["password"]);                                       // Do not trim the password, let the user input whatever they desire
$confirmPssword = htmlspecialchars($_POST["c-password"]);                               // Do not trim the password, let the user input whatever they desire
$position = trim(preg_replace('/\s+/', ' ', htmlspecialchars($_POST["position"])));

if (empty($username))
{
    echo "Invalid username!";
} else
if (empty($password))
{
    echo "Invalid password!";
} else
if ($confirmPssword != $password)
{
    echo "Password/Confirm Password didn't match!";
} else {
    $sql = get_user_details($username);
    $result = $conn->query($sql);

    if ($result)
    {
        if ($result->num_rows > 0)
        {
            $result->close();
            echo "username is already registered";
        } else {
            // Generate a new random salt
            $salt = '$1$' . substr(strtr(base64_encode(random_bytes(32)), '+', '.'), 0, 8) . '$';

            // Generate the MD5 hashed password
            $cryptedPassword = crypt($password, $salt);

            $sql = add_user($username, $cryptedPassword, $position);
            if ($conn->query($sql))
            {
                echo "done";
            } else {
                echo "please refresh the page and try again";
            }
        }
    } else {
        echo "please refresh the page and try again";
    }

    $conn->close();
}

我正在使用这个:https://code.jquery.com/jquery-3.1.1.min.js

我在哪里可以获得有关 cpanel 错误的更多具体信息?

网络标签:

Server  
nginx/1.14.1
Date    
Mon, 24 Jun 2019 14:44:51 GMT
Content-Type    
text/html; charset=UTF-8
Content-Length  
0
Connection  
keep-alive
Expires 
Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control   
no-store, no-cache, must-reval…te, post-check=0, pre-check=0
Pragma  
no-cache
Request headers (542 B) 
Host    
(WEBSITE)
User-Agent  
Mozilla/5.0 (Windows NT 10.0; …Firefox/56.0 Waterfox/56.2.11
Accept  
*/*
Accept-Language 
en-US,en;q=0.5
Accept-Encoding 
gzip, deflate
Referer 
http://(WEBSITE)/register.php
Content-Type    
application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With    
XMLHttpRequest
Content-Length  
53
Cookie  
PHPSESSID=v1qp6qo01igqlho8668sch2mu5
Connection  
keep-alive
Pragma  
no-cache
Cache-Control   
no-cache

“响应”下没有显示任何内容

最佳答案

好吧,无论如何它现在可以工作了。我刚刚将 PHP 版本从默认的 5.6 更改为 7.0..

关于javascript - 在 Cpanel 上使用 Javascript AJAX POST 时出现 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56739293/

相关文章:

javascript - 安装 npm install mysql 后,从哪里获取 mysql 的用户名和密码?

php - Jquery 自动完成文本字段,动态添加的行中具有数据属性

php - 从 iOS 应用程序发送帖子到 php 脚本不起作用...简单的解决方案很可能

javascript - 测试图形用户界面

javascript - 使用jquery在父div中创建子div

javascript - ajax 提交后清除表单值。

javascript - 重新格式化 json 数据中的字符

javascript - 如何仅注销我的 FB 应用程序而不是我的 Facebook 帐户?

javascript - 在内部文本之前插入子元素

javascript - d3.js: parent 的大小= child 的大小之和