使用ajax变量和发布

时间:2015-04-21 11:01:11

标签: javascript php jquery html ajax

我有以下ajax功能:

$("#signInButton2").click(function() {
   $.ajax({
    type: "POST",
    data: {couponcode: $('#couponCode').val(), userEmail: $('#login-username').val() },
    url: 'coursePayment.php',
    success: function (response) {//response is value returned from php (for    your example it's "bye bye"

    }
   });
});

我的问题如下:

  1. 似乎没有向coursePayment.php发送任何内容。
  2. userEmail可以在login-username和registration,username中引用,如何将id与userEmail变量相关联
  3. 基本上类似于第2点。我有couponCodeRegisterAmount,我有couponCodeLoginAmount ID,我想与一个名为couponCodeAmount的帖子变量关联,我希望能够在coursePayment页面上检索
  4. 如有任何澄清,请告诉我们谢谢

    更新HTML

    <input type="text" oninput="calculate()" name="couponCode"  id="couponCode"  value="" placeholder="Please Enter Coupon Code" required>
    
    
    <?php ?>
    <script>
    $("#signInButton2").click(function() {
       $.ajax({
        type: "POST",
        data: {couponcode: $('#couponCode').val(), userEmail: $('#login-username').val() },
        url: 'coursePayment.php',
        success: function (response) {//response is value returned from php (for    your example it's "bye bye"
    
        }
       });
    });
    
     </script>
    
    <div class="container">    
            <div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">                    
                <div class="panel panel-info" >
                        <div class="panel-heading">
                            <div class="panel-title"><h4><b>Sign In to Proceed with Purchase</b></h4></div>
                        <h4 id="loginError" style="color:red;"></h4>
    
    
                        </div>     
                            <h4>   Don't have an account! 
                                            <a href="#" onClick="$('#loginbox').hide(); $('#signupbox').show()">
                                                Sign Up Here
                                            </a></h4>
    
                        <div style="padding-top:30px" class="panel-body" >
    
                            <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
    
    
                            <form method="post" action="">  
                                <!--Coupon Code -->
                            <input type="hidden" id="couponCodeLogin" name="couponCodeLogin">
                                 <input type="hidden" id="couponCodeLoginAmount" name="couponCodeLoginAmount">   
    
                                <div style="margin-bottom: 25px" class="input-group">
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                            <input id="login-username" type="text" class="form-control" name="email" value="" placeholder="username or email">                                        
                                        </div>
    
                                <div style="margin-bottom: 25px" class="input-group">
                                            <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                            <input id="login-password" type="password" class="form-control" name="pass" placeholder="password">
                                        </div>
    
    
    
                                <div class="input-group">
                                          <div class="checkbox">
                                            <label>
                                              <input id="login-remember" type="checkbox" name="remember" value="1"> Remember me
                                            </label>
                                            <label><a href="#">Forgot password?</a></label>
    
                                          </div>
                                        </div>
    
    
                                    <div style="margin-top:10px" class="form-group">
                                        <!-- Button -->
    
                                        <div class="col-sm-12 controls">
                                          <input id="signInButton2" class="btn btn-danger" name="login" type="submit" value="Sign In">
    
                                        </div>
                                    </div>
    
    
    
                                </form>     
    
    
    
                            </div>                     
                        </div>  
            </div>
    
    
    
            <div id="signupbox" style="display:none; margin-top:50px" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
                        <div class="panel panel-info">
                            <div class="panel-heading">
                            <div class="panel-title"><h4>Sign Up</h4></div>
                            <h4 id="registerError" style="color:red;"></h4>
    
                                <div style="float:right; font-size: 85%; position: relative; top: -35px"><a id="signinlink" href="#" onclick="$('#signupbox').hide(); $('#loginbox').show()"><h4>Sign In</h4></a></div>
                            </div>  
                            <div class="panel-body" >
                                <form id="signupform" action="" method="post" class="form-horizontal" role="form">
    
                                    <div id="signupalert" style="display:none" class="alert alert-danger">
                                        <p>Error:</p>
                                        <span></span>
                                    </div>
    
                                    <input type="hidden" id="couponCodeRegister" name="couponCodeRegister">
                                 <input type="hidden" id="couponCodeRegisterAmount" name="couponCodeRegisterAmount">
    
    
    
    
                                    <div class="form-group">
                                        <label for="firstname" class="col-md-3 control-label">First Name</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="fname" placeholder="First Name">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="lastname" class="col-md-3 control-label">Last Name</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="lname" placeholder="Last Name">
                                        </div>
                                    </div>
    
                                     <div class="form-group">
                                        <label for="email" class="col-md-3 control-label">Email</label>
                                        <div class="col-md-9">
                                            <input type="text" id="emailSignup" class="form-control" name="email" placeholder="Email Address">
                                        </div>
                                    </div>
    
                                     <div class="form-group">
                                        <label for="email" class="col-md-3 control-label">Phone Number</label>
                                        <div class="col-md-9">
                                            <input type="number" class="form-control" name="pnumber" placeholder="Phone Number">
                                        </div>
                                    </div>
    
                                    <div class="form-group">
                                        <label for="password" class="col-md-3 control-label">Password</label>
                                        <div class="col-md-9">
                                            <input type="password" class="form-control" name="pass" placeholder="Password">
                                        </div>
                                    </div>
    
                                    <div class="form-group">
                                        <label for="icode" class="col-md-3 control-label">Company Name</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="cname" placeholder="Company Name (Optional)">
                                        </div>
                                    </div>
    
                                      <div class="form-group">
                                        <label for="icode" class="col-md-3 control-label">Position</label>
                                        <div class="col-md-9">
                                            <input type="text" class="form-control" name="cposition" placeholder="Position (Optional)">
                                        </div>
                                    </div>
    
                                    <div class="form-group">
                                        <!-- Button -->                                        
                                        <div >
                                            <input id="signInButton" class="btn btn-danger" name="register" type="submit" value="Sign Up">
                                        </div>
                                    </div>
    
                                    <div style="border-top: 1px solid #999; padding-top:20px"  class="form-group">
    
    
    
                                    </div>
    
    
    
                                </form>
                             </div>
                        </div>
    
    
    
                   </div> 
             </div> 
         <!-- register -->
    

0 个答案:

没有答案