我正在尝试使用jQuery发送表单的数据。但是,数据无法到达服务器,并且它继续使用GET
函数来获取./?page=game&mode=search&type=private并且它不断获取该页面并且不会停止获取它。你能告诉我我做错了什么吗?
腓:
if (isset($_GET['type'])) {
$type = $secure->clean($_GET['type']);
} else {
$type = '';
}
if ($type == 'private') {
if ( isset($_POST['submit'])) {
$name = $secure->clean($_REQUEST['name']);
$checkuser = $db->fetch("SELECT * FROM accounts WHERE name == '$name''");
if ($checkuser) {
$data ='<h1> The user you searched for does not exist. </h1>
<a class="goback message" href="#">Continue</a>';
}
} else {
$checkMatch = $db->query("SELECT * FROM accounts WHERE `id` = '".$account['id']."'");
while ($info = mysql_fetch_array($checkMatch)) {
$status = $info['status'];
$gameid = $info['gameid'];
}
if($status = 'NULL') {
$data ='<h1> Who do you want to battle against? </h1><br />
<form action="" method="post" id="form-pb" name="pb" target="_self" >
USERNAME:<input name="name" type="text" size="40" maxlength="40" />
<input name="submit" type="submit" value="Search"/>
</form>
<a class="goback" href="#">Cancel</a>';
}
}
echo $data;
exit;
}
Javascripit
case 'submit':
$.post('./?page=game&mode=search&type=private', $("#form-pb").serialize(), function(data){
var $response=$(data);
var error = $response.filter('h3').text();
$('.search').html(data);
if(!error){
match = setInterval(function(){
if(!$('.search').length){
$('#main_container').prepend('<div id="popup"><div class="opacity"></div><div class="search"></div></div>');
}
$('.search').load('./?page=game&mode=search&type=private', function(){
var meta = $('#stopMe').attr('content'); var meta = $('#stopMe').attr('content');
if(meta){
meta = meta.split("URL="), meta = meta[1];
window.location = meta;
}
});
},1000);
}
});
break;
表格是
<form action="" method="post" id="form-pb" name="pb" target="_self" >
USERNAME:<input name="name" type="text" size="40" maxlength="40" />
<input name="submit" type="submit" value="Search"/>
</form>
答案 0 :(得分:0)
你需要解决这个问题:
$checkuser = $db->fetch("SELECT * FROM accounts WHERE name == '$name''");
这样的事情:
$checkuser_res=$db->query("SELECT * FROM accounts WHERE name == '$name''");
if($checkuser_res->num_rows==1)
{
// The user exists
}
else
{
// The user doesn't exist
}
为此,我假设您使用的是mysqli,如果它是一个特殊的mysql包装器,那么您的代码也可能有效。