带有jQuery POST的引导模式

时间:2015-10-29 作者:csharpdude77

我试图创建一个带有验证的弹出窗口和表单,但出于某种原因,这一过程。php没有找到,我被告知要重新回答我的问题。

我正在使用下面的jQuery转到我的处理文件:

<div id="thanks" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Redeem Points</h4>
    </div>
    <div class="modal-body">
        <form class="form-horizontal" class="contact" name="commentform" method="post" action="<?php 
            bloginfo(\'template_url\'); ?>/sendredeempoints.php" enctype="multipart/form-data">
                <div class="form-group">
            <h3>You may only redeem the maxium points of : <?php echo $maxpoints;?></h3>
            <input type="hidden" name="playerid" value="<?php echo $playerId;;?>" />
            <input type="number" valuemax="<?php echo $maxpoints;
                ?>" name="points" class="form-control" placeholder="How many points do you wish to redeem." />                  
            <label class="control-label col-md-4" for="Comments">Comments?</label>
        </div>
        <div class="form-group">
            <div class="col-md-6">
                <button title="" data-original-title="" type="submit" value="Submit" class="btn btn-custom pull-right" id="send_btn">Send</button>
                <div style="top: -4px; left: 279px; display: block;" class="popover fade right in">
                    <div class="arrow"></div>
                    <h3 style="display: none;" class="popover-title"></h3>
                    <div class="popover-content">Thank You</div>
                </div>
            </div>
        </div>
        </form>
    </div><!-- End of Modal body -->
    </div><!-- End of Modal content -->
    </div><!-- End of Modal dialog -->
</div><!-- End of Modal --> 

<script>
$(function() {
    //twitter bootstrap script
    $("button#submit").click(function(){
        $.ajax({
            type: "POST",
            url: "process.php",
            data: $(\'form.contact\').serialize(),
            success: function(msg){
                $("#thanks").html(msg)
                $("#form-content").modal(\'hide\'); 
            },
            error: function(){
                alert("failure");
            }
        });
    });
});
</script>
过程。php

$playerid = $_POST[\'playerid\']; // required        
$points = $_POST[\'points\']; // required
$mymessage = $_POST[\'userMessage\']; // required    
$email_from = \'[email protected]\';
$email_subject = $_POST[\'mysubject\'];
$email_to = $_POST[\'toEmail\'];

$headers = \'From: \' . $email_from . "\\r\\n" .
    \'Reply-To: \' . $email_from . "\\r\\n" .
    \'X-Mailer: PHP/\' . phpversion();
@mail( $email_to, $email_subject, $mymessage, $headers );

1 个回复
SO网友:Tobias Beuving

If流程。找不到php,文件中的引用不正确。确保引用了正确的路径,例如istance-如果文件位于站点的根目录中,请在代码前添加斜杠:

url: "process.php",

将是:

url: "/process.php",

如果它位于“ajax”目录中:

url: "/ajax/process.php",

我自己通常会提供完整的路径:

url: "http://myserver.bla/process.php",

希望这有帮助