更新jQuery的AJAX的形式表,数据库查询提交数据库查询、形式、jQuery、AJAX

2023-09-10 18:58:37 作者:空巷°

下面是我...

 函数CHECKDB(code,用户ID)
    {
      $(#notice_div)HTML(中..')。
      $阿贾克斯({
      键入:POST,
      网址:< PHP代码bloginfo('template_url');> /profile/check_$c$c.php?,
      数据:{code:code,用户ID:用户ID},
      //数据:'code ='+ code +'和;用户id ='+用户ID,
      数据类型:HTML,
      成功:函数(结果){

           如果(结果== 0)
            {
                $('#成功)HTML(code +'已经赎回!);
                //警报(成功); //测试的目的
            }
            否则,如果(结果== 2)
            {
                $('#ERR)HTML(code +'已经存在,并已兑现....');
                //警报('故障'); //测试目的
            }否则,如果(结果== 1){
                $('#ERR)HTML(code +'赎回code犯规存在');
            }
            $(#notice_div)的HTML('')。
            // $('#originalquery)隐藏()。
            //$('#mainquery').fadeIn('slow');
            //$("#originalquery").replaceWith($('#mainquery',$(HTML)));

            //警报(结果);
          }
      })

    }
 

这是在同一个页面,因为这对:

 < PHP

$ SQL =SELECT * FROM wp_scloyalty其中userid ='$ USER_ID';
$结果= mysql_query($ SQL);
?>
<表ID =便便的风格=保证金:10px的0px 0px 0px; WIDTH =100%的边界=0的cellpadding =0CELLSPACING =0>
&其中; TR>
    < TD><强>产品< / STRONG>< / TD>
    < TD><强> code< / STRONG>< / TD>
    < TD><强>值小于; / STRONG>< / TD>
< / TR>
<?PHP而($行= mysql_fetch_array($结果)){>
&其中; TR>
    < TD>&LT ;?回声$行['产品']; ?>< / TD>
    < TD>&LT ;?回声$行['code']; ?>< / TD>
    < TD>&LT ;?回声$行['值']; ?>< / TD>
< / TR>
&LT ;? ?}>
< /表>


            <形式方法=后级=sc_ajaxxxID =sc_add_voucherxNAME =sc_ajax行动=的onsubmit =CHECKDB(document.sc_ajax.sc_voucher_ code.value,<?PHP的echo $ USER_ID;?>);返回false;>

            <按钮ID =呈交code型=提交>提交< /按钮>

        < /形式GT;
 
jquery里ajax中怎么将函数中的数据提取出来,放在另外一个其他函数中使用

这是HTML ...

在Ajax请求被提交,我想表自动显示新添加的信息。我知道为什么它不工作,但不知道如何得到它刷新。我想刷新DIV心不是真的有可能,因为我想它是..即时通讯想着做一个新的查询,并成功函数把它吗?

感谢:)

修改

表查询:

 < PHP

$ SQL =SELECT * FROM wp_scloyalty其中userid ='$ USER_ID';
$结果= mysql_query($ SQL);
?>
<表ID =便便的风格=保证金:10px的0px 0px 0px; WIDTH =100%的边界=0的cellpadding =0CELLSPACING =0>
&其中; TR>
    < TD><强>产品< / STRONG>< / TD>
    < TD><强> code< / STRONG>< / TD>
    < TD><强>值小于; / STRONG>< / TD>
< / TR>
<?PHP而($行= mysql_fetch_array($结果)){>
&其中; TR>
    < TD>&LT ;?回声$行['产品']; ?>< / TD>
    < TD>&LT ;?回声$行['code']; ?>< / TD>
    < TD>&LT ;?回声$行['值']; ?>< / TD>
< / TR>
&LT ;? ?}>
< D​​IV ID =新的code>< / DIV>
< /表>
 

解决方案

所以基本上要根据 $ USER_ID 从数据库中提取的记录,并由此产生生成的表的需求要显示在页面请求使用Ajax?对?

  

显示新添加的信息

在哪里是它被添加呢?

Here is what I have...

function checkDB(code, userid)
    {
      $("#notice_div").html('Loading..'); 
      $.ajax({
      type: "POST",
      url: "<?php bloginfo('template_url'); ?>/profile/check_code.php",
      data: { code: code, userid: userid},
      //data: 'code='+code+'&userid='+userid,
      datatype: "html",
      success: function(result){

           if(result == 0)
            {
                $('#success').html( code + ' has been redeemed!');
                // alert('success');//testing purposes
            }
            else if(result == 2)
            {
                $('#err').html(  code + ' already exists and has already been redeemed....');
                //alert('fail');//testing purposes
            }else if(result == 1){
                $('#err').html(  code + ' redeem code doesnt exist');      
            }
            $("#notice_div").html(''); 
            //$('#originalquery').hide();
            //$('#mainquery').fadeIn('slow');
            //$("#originalquery").replaceWith($('#mainquery', $(html)));

            //alert(result);        
          }
      })

    }

This is on the same page as this:

   <?php

$sql="SELECT * FROM wp_scloyalty WHERE userid = '$user_id'";
$result=mysql_query($sql);
?> 
<table id="poo" style="margin:10px 0px 0px 0px;" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><strong>Product</strong></td>
    <td><strong>Code</strong></td>
    <td><strong>Value</strong></td>
</tr>
<?php while($rows=mysql_fetch_array($result)){ ?>  
<tr>
    <td><? echo $rows['product']; ?></td>
    <td><? echo $rows['code']; ?></td>
    <td><? echo $rows['value']; ?></td>
</tr>  
<? } ?>
</table>


            <form method="post" class="sc_ajaxxx" id="sc_add_voucherx" name="sc_ajax" action="" onsubmit="checkDB(document.sc_ajax.sc_voucher_code.value, <?php echo $user_id; ?>); return false;">

            <button id="submit-code" type="submit" >Submit</button>

        </form>

This is the HTML...

When the ajax request is submitted, I want the table to automatically show the newly added information. I know why its not working but not sure how to get it to refresh. I assume refreshing the div isnt really possible as I would like it to be.. Im thinking about making a new query and bringing it in on success function?

Thanks :)

EDIT

The table query:

 <?php

$sql="SELECT * FROM wp_scloyalty WHERE userid = '$user_id'";
$result=mysql_query($sql);
?> 
<table id="poo" style="margin:10px 0px 0px 0px;" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><strong>Product</strong></td>
    <td><strong>Code</strong></td>
    <td><strong>Value</strong></td>
</tr>
<?php while($rows=mysql_fetch_array($result)){ ?>  
<tr>
    <td><? echo $rows['product']; ?></td>
    <td><? echo $rows['code']; ?></td>
    <td><? echo $rows['value']; ?></td>
</tr>  
<? } ?>
<div id="newCode"></div>
</table>

解决方案

so basically you want to pull the record from database based on $user_id and the resulting generated table needs to be shown on requesting page with ajax? Right?

show the newly added information

where's it being added anyway?