使用Jquery和Ajax时联系表单不起作用,但删除后工作正常

时间:2017-09-08 13:11:19

标签: javascript php jquery ajax

我在laravel工作并尝试发送邮件它工作正常但是当我使用JQuery文件时它说

POST http://localhost:8080/JobScholar/send_inquiry 405 (Method Not Allowed)

表格代码工作正常

<form action="{{'send_inquiry'}}" method="post"
  id="contact-form" class="contact-form">
  {{method_field('GET')}}
  {{csrf_field()}}
  <div class="form-group-wrapper flex space-between items-center">
    <div class="form-group">
        <p class="label">Your Name*</p>
        <input type="text" id="contact-name" name="contact-name"
               placeholder="Enter your name" required="">
    </div> <!-- end .form-group -->
    <div class="form-group">
        <p class="label">Your Email*</p>
        <input type="email" id="contact-email" name="contact-email"
               placeholder="Enter your email" required="">
    </div> <!-- end .form-group -->
  </div> <!-- end .form-group-wrapper -->

  <div class="form-group textarea">
    <p class="label">Your Message*</p>
    <textarea name="contact-message" id="contact-message" required="" rows="6"
              placeholder="Here goes your message"></textarea>
  </div> <!-- end .form-group -->
  <button type="submit" class="button" data-text="Submit">Send us</button>

  <div id="contact-loading" class="alert alert-info form-alert">
    <span class="message">Loading...</span>
  </div>
  <div id="contact-success" class="alert alert-success form-alert">
    <span class="message">Success!</span>
  </div>
  <div id="contact-error" class="alert alert-danger form-alert">
    <span class="message">Error!</span>
  </div>
</form>

但是当我使用jquery文件时

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>

我收到以下异常

POST http://localhost:8080/JobScholar/send_inquiry 405 (Method Not Allowed)
send @ jquery-3.2.1.min.js:4
ajax @ jquery-3.2.1.min.js:4
(anonymous) @ scripts.js:243
dispatch @ jquery-3.2.1.min.js:3
q.handle @ jquery-3.2.1.min.js:3

Jquery文件链接

https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js

并且此错误位于此文件行3954 send

h.send(b.hasContent && b.data || null) 

错误第3789行同一文件ajax

e.send(v, A)

错误行245 anonomous

/*==========  Contact Form  ==========*/

    $('#contact-form').on('submit', function() {
        $('#contact-error').fadeOut();
        $('#contact-success').fadeOut();
        $('#contact-loading').fadeOut();
        $('#contact-loading').fadeIn();
        if (validateEmail($('#contact-email').val()) && $('#contact-email').val().length !== 0 && $('#contact-name').val().length !== 0 && $('#contact-message').val().length !== 0) {
            var action = $(this).attr('action');
            $.ajax({
                type: "POST",
                url : action,
                data: {
                    contact_name: $('#contact-name').val(),
                    contact_email: $('#contact-email').val(),
                    contact_phone: $('#contact-phone').val(),
                    contact_message: $('#contact-message').val()
                },
                success: function() {
                    $('#contact-error').fadeOut();
                    $('#contact-success').fadeOut();
                    $('#contact-loading').fadeOut();
                    $('#contact-success .message').html('Success! Thanks for contacting us!');
                    $('#contact-success').fadeIn();
                },
                error: function() {
                    $('#contact-error').fadeOut();
                    $('#contact-success').fadeOut();
                    $('#contact-loading').fadeOut();
                    $('#contact-error .message').html('Sorry, an error occurred.');
                    $('#contact-error').fadeIn();
                }
            });
        } else if (!validateEmail($('#contact-email').val()) && $('#contact-email').val().length !== 0 && $('#contact-name').val().length !== 0 && $('#contact-message').val().length !== 0) {
            $('#contact-error').fadeOut();
            $('#contact-success').fadeOut();
            $('#contact-loading').fadeOut();
            $('#contact-error .message').html('Please enter a valid email.');
            $('#contact-error').fadeIn();
        } else {
            $('#contact-error').fadeOut();
            $('#contact-success').fadeOut();
            $('#contact-loading').fadeOut();
            $('#contact-error .message').html('Please fill out all the fields.');
            $('#contact-error').fadeIn();
        }
        return false;
    });

第2067行dispatch

e = ((r.event.special[g.origType] || {}).handle || g.handler).apply(f.elem, i),

line 1993n error q.hanlde

 return "undefined" != typeof r && r.event.triggered !== b.type ? r.event.dispatch.apply(a, arguments) : void 0

0 个答案:

没有答案