簡體   English   中英

使用jQuery POST和php序列化和提交表單不起作用

[英]serializing and submitting a form with jQuery POST and php isn't working

我正在嘗試使用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;   

    }

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>

您需要解決此問題:

$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包裝器,則您的代碼也可能有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM