0

我正在尝试使用 jQuery 发送表单的数据。但是,数据没有到达服务器,它继续使用该GET函数来获取 ./?page=game&mode=search&type=private 并且它一直在获取该页面并且不会停止获取它。你能告诉我我做错了什么吗?

php:

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;   

    }

Java脚本

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>
4

1 回答 1

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 包装器,那么您的代码可能也可以工作。

于 2013-10-25T23:29:25.110 回答