doupa8922 2012-07-20 05:51 采纳率: 100%
浏览 63
已采纳

使用Jquery / $ .ajax和php验证

I have a form with radios and trying to validate starting with jq/$.ajax and then posting info in php.

form.php

<tr>
  <td class="h"><span class="txt_wht">t1</span></td>
        <input type="hidden" name="gm[0]" value="t1" />
  <td class="vs"><span class="txt_yel_sm">vs</span></td>
  <td class="a"><span class="txt_wht">t2</span></td>
        <input type="hidden" name="gm[1]" value="t2" />

  <td><input type="radio" name="g1" value="a" /></td>
  <td><input type="radio" name="g1" value="b" /></td>
  <td><input type="radio" name="g1" value="c" /></td>
  </tr>
<tr>
  <td class="h"><span class="txt_wht">t1</span></td>
        <input type="hidden" name="gm[0]" value="t1" />
  <td class="vs"><span class="txt_yel_sm">vs</span></td>
  <td class="a"><span class="txt_wht">t2</span></td>
        <input type="hidden" name="gm[1]" value="t2" />

  <td><input type="radio" name="g2" value="a" /></td>
  <td><input type="radio" name="g2" value="b" /></td>
  <td><input type="radio" name="g2" value="c" /></td>
 </tr>

validade.js

$(document).ready(function () {
    //global vars

    form.submit(function () {
        if (validate1() && validate2()) {
            //vars
            var exst_email = $('#exst_email').attr('value');
            var g1 = $("input[name='g1']:checked").attr('value');
            //more vars

            $.ajax({
                type: "post",
                url: "scripts/sbmt.php",
                data: "exst_email=" + exst_email,
                success: function (exst_rsp) {

                    //if its not exist
                    if (exst_rsp == "not_exist") {
                        valInfo.text("Error1!");
                        valInfo.addClass("error");
                        email_reg_err = true;
                    } else {
                        valInfo.text("");
                        valInfo.removeClass("error");
                        email_reg_err = false;
                    }
                    //more validation with error msgs

                    //validate 1 & validate 2 functions

and sbmt.php

session_start();
// connect to db
require_once('conn.php');

if($stmt = $mysqli->prepare('SELECT email FROM table WHERE email=?')){
   $stmt->bind_param("s", $_POST['exst_email']); 
   $stmt->execute();
   $stmt->store_result();

   $numRows = $stmt->num_rows();
   if($numRows < 1){
       echo 'not_exist';
       exit();
   }
   $stmt->close();
}
//more validation

Now,

  1. Due to Dreamweaver, I know that I don't have typing errors or unclosed tags.

  2. My validate 1 & 2 functions are working fine.

  3. Due to firebug,

    a) I know that my data are posted in sbmt.php

    b) I get no response back to display the error msg.

I am validating 3 more forms (textareas only if it matters) using the exact same way (differentjs/php files) and they are working fine!

Any suggestion on what may be wrong here?

  • 写回答

2条回答 默认 最新

  • duanbai5348 2012-07-20 08:35
    关注

    SOLVED

    I don't know why but here's the fix:

    I wasn't passing to sbmt.php the <input type="hidden"> values since I didn't use them at the moment.

    But I desided to post them as well to see if it does any good. And it worked!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架