Javascript 未定义AJAX脚本错误未捕获引用错误函数

Javascript 未定义AJAX脚本错误未捕获引用错误函数,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有以下脚本,它阻止表单提交,然后使用ajax调用页面 这是我的表格 <form method="post" action="makeBid.php" name="apply" id="makeBid"> <label for="amount">Bid Amount</label> <input type="text" id="amount" name="amount" placeholde

我有以下脚本,它阻止表单提交,然后使用ajax调用页面

这是我的表格

<form method="post" action="makeBid.php" name="apply" id="makeBid">
                <label for="amount">Bid Amount</label>
                <input type="text" id="amount" name="amount" placeholder="Enter Bid Amount"/>
                <label for="completionDate">Completion Date</label>
                <input type="text" id="completionDate" name="completionDate" placeholder="Completion Date"/>
                <label for="apply">Support Your Application</label>
                <textarea name="msg" id="msg" class="application" placeholder="Enter A Message To Support Your Application"></textarea>
                <button name="apply" id="apply" value="<?php echo $_POST['btnSubmit'] ?>" class="btn btndanger">Apply</button>
        </form>
if(isset($_POST['apply'])) {
    require_once('../controller/bids.php');
    $bid = new Bid();
    $bid->setAmount($_POST['amount']);
    $amount = $bid->getAmount();
    $bid->setDate($_POST['completionDate']);
    $date = $bid->getDate();
    $bid->setRemarks($_POST['msg']);
    $msg = $bid->getRemarks();

    echo $bid->processBid($_SESSION['userID'], $_POST['apply'],$amount, $date, $msg);
}

投标金额
竣工日期
支持您的应用程序
看起来不错

只需检查您是否正确打开了
标记,因为在示例中没有

如果你能复制错误并在这里发布,可能会更有用

这里有两件事不对:


  • PHP代码需要以
    开头。当jQuery未加载且函数尝试运行时,可能会发生这种情况。为此,让我看看jQuery是否在我的脚本
    之前加载。这是我的表单
    -您已在HTML中取消转义PHP?是否检查了以下内容
     $(function () {
                var form = $('#makeBid');
                var formMessages = $('#formResult');
    
                // Set up an event listener for the contact form.
                $(form).submit(function (e) {
                    // Stop the browser from submitting the form.
                    e.preventDefault();
    
                    // Serialize the form data.
                    var formData = $(form).serialize();
    
                    // Submit the form using AJAX.
                    $.ajax({
                        type: 'POST',
                        url: $(form).attr('action'),
                        data: formData
                    }).done(function (response) {
                        // Make sure that the formMessages div has the 'success' class.
                        $(formMessages).removeClass('error').addClass('success');
    
                        // Set the message text.
                        $(formMessages).html(response); // < html();
    
                        // Clear the form.
                        $('').val('')
                    }).fail(function (data) {
                        // Make sure that the formMessages div has the 'error' class.
                        $(formMessages).removeClass('success').addClass('error');
    
                        // Set the message text.
                        var messageHtml = data.responseText !== '' ? data.responseText : 'Oops! An error occured and your message could not be sent.';
                        $(formMessages).html(messageHtml); // < html()
                    });
    
                });
            });
        </script>