weixin_33692284 2017-06-23 13:08 采纳率: 0%
浏览 5

如何进行Ajax呼叫[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/1210380/500-internal-server-error" dir="ltr">500 Internal Server Error?</a>
                            <span class="question-originals-answer-count">
                                (5 answers)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/2687730/how-can-i-make-php-display-the-error-instead-of-giving-me-500-internal-server-er" dir="ltr">How can I make PHP display the error instead of giving me 500 Internal Server Error [duplicate]</a>
                            <span class="question-originals-answer-count">
                                (7 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-06-23 13:13:58Z" class="relativetime">2 years ago</span>.</div>
        </div>
    </aside>

I have a form just to submit an email into a custom table of wp_wpa_watchlist.

The Form html is:

<form name="anyreg" id="any_reg" method="post">
                    <table>
                    <tr>
<td><input type="text" name="email" id="mail" placeholder="Enter Your Email"></td>
            <input type="hidden" name="id" value="<?php echo $auction ?>">
            <td><input type="submit" name="submitmail" id="submitmail" value="Submit"></td>
            </tr>

validation code + ajax call code is:

<script type="text/javascript">
$('#submitmail').click(function(event){

            event.preventDefault();

            var tre = true;


 var anymail = document.getElementById("mail").value;
            var atpos = anymail.indexOf("@");
            var dotpos = anymail.lastIndexOf(".");

                if (anymail==null || anymail=="")
                    {  
                    alert("Email cannot be Empty");
                    tre =false;  
                    }

                else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=anymail.length) 
                    {
                    alert("Please Enter A Valid Email Address");
                    tre =false;
                     }
            if(tre == true){
        $.ajax({url: '<?php echo $ajaxUrl; ?>',method:'POST',
                data:$('#any_reg').serialize()
                ,success: function(result){
                    if (result== 'INSERTED'){
                        alert("SUCCESS");   
                    }else
                    {
                        alert("Failed");
                    }

                },

        });
}
});
</script>

And My the ajax call file contains the following query:

<?php 
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );

global $wpdb;

$email=$_POST['email'];
$auction=intval($_GET['ID']);

if(!email_exists( $email ))
{
        $insert = "INSERT INTO wp_wpa_watchlist (auction_id,watch_email) VALUES('".$auction."', '".$email."')";
        $dbin = $wpdb -> query($insert);    

        if($dbin){
            echo "INSERTED";
        }
        else{
            echo "ERROR";
        }

}

else if 
    { 
        echo "Email Already Exists";
    }

?>

am very much newbie when it comes to ajax and ajax call. My problem is ajax call isnt happening. When i checked the console its showing Internal Error 500. Anyone please guide me

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于知识的学以致用的解释
    • ¥50 三种调度算法报错 有实例
    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败