gpt4 book ai didi

php - Jquery AJAX 未在 PHP 上传递 “POST” 数据

转载 作者:行者123 更新时间:2023-11-29 11:10:22 25 4
gpt4 key购买 nike

function getHash() {
alert('Debug me gethash');
return localStorage.getItem('hash');
}

function getUser() {
return getHash().split('~')[0];
}

function setHash(data) {
alert('Debug sethash');
localStorage.setItem('hash', data);
}

function doAction(action, params, callback) {
alert('Debug me 3');
$.post('../core.php?action=' + action + '&hash=' + getHash(), params, callback);
}

function register() {
alert('debug1');
doAction('register', {
username: $('#register_user').val(),
ref: fromUrl('ref')
}, function(data) {
alert('Debug me 2');
var json = JSON.parse(data);
if (json.hasOwnProperty('error'))
alert(json.error);
else
ready(json);
});
}
$db=new PDO('mysql:dbname=name;host=localhost',
'',
'',
array(PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION));
switch ($_GET['action']) {
case'register': if(isset($_POST['username'], $_POST['ref'])) {
$username=$_POST['username'];
if(strlen($username) < 3) error('Username is too short!');
if(strlen($username) > 10) error('Username is too long!'); //N
if(!preg_match('/^[a-zA-Z0-9_]+$/', $username)) error('Username contains invalid characters!');
$ret=$db->prepare("SELECT * FROM users WHERE username=?");
$ret->execute(array($username));
if($ret->fetch()) error('Username already exists!');
$hash=md5(uniqid("", true));
$db->prepare("INSERT INTO users(username,hash,ontime,referral) VALUES(?,?,?,?)")->execute(array($username, $hash, time(), (int)$_POST['ref']));
die(json_encode(array('hash'=>$username.'~'.$hash)));
}
;
}
 <h2 class="dialog_text">Register</h2>
<input type="text" class="form-control-modal" placeholder="Username" id="register_user">
<button type="button" class="btn btn-modalbuy" class="close" onclick="register()">Sign Up</button>
<div class='smalltext'>By accessing the site I verify that I am at least 18 years old and have read the Terms & Conditions.</div>
<br>
<hr>//PHPCOde $db = new PDO('mysql:dbname=name;host=localhost', '', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); switch ($_GET['action']) { case 'register': if(isset($_POST['username'],$_POST['ref'])) { $username = $_POST['username']; if(strlen($username)
<
3) error( 'Username is too short!'); if(strlen($username)>10) error('Username is too long!'); //N if(!preg_match('/^[a-zA-Z0-9_]+$/',$username)) error('Username contains invalid characters!'); $ret = $db->prepare("SELECT * FROM users WHERE username=?"); $ret->execute(array($username)); if($ret->fetch()) error('Username
already exists!'); $hash = md5(uniqid("",true)); $db->prepare("INSERT INTO users(username,hash,ontime,referral) VALUES(?,?,?,?)")->execute(array($username,$hash,time(),(int)$_POST['ref'])); die(json_encode(array('hash'=>$username.'~'.$hash))); }; }

我收到 POST http://localhost/core.php?action=register&hash=null 500(内部服务器错误)和 XHR 完成加载:POST“http://localhost/core.php?action=register&hash=null”。

不太确定是我的服务器还是代码。但我似乎无法让它发挥作用。今天花了 4 个小时尝试。

最佳答案

如果代码存在 fatal error 但错误报告已关闭,则会显示 500 内部服务器错误

通过php文件打开错误报告:

ini_set('display_errors', 1);

通过 htacces 文件打开错误报告:

php_flag display_errors 1

关于php - Jquery AJAX 未在 PHP 上传递 “POST” 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40688552/

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