Ajax没有被调用 [英] Ajax not being called

查看:139
本文介绍了Ajax没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用HTML编写了一个带有三个文本框的小表格.这个想法是创建一个联系我"表单,该表单将使用NodeMailer提交的信息.但是,我的ajax函数没有被调用.更具体地说,该信息不会发送到NodeMailer所在的"/time". 任何指针"在此先感谢!这是我的JS文件:

I wrote a little form in HTML with three textboxes. The idea is to create a "Contact me" form that is going to use the information submitted, by NodeMailer. However, my ajax function is not being called. To be more specific, the info is not being sent to "/time" where the NodeMailer is. Any "pointers" Thanks in advance! Heres my JS file:

$(document).ready(function(){
    $("#send").click(function(e){ 

        var name = $('input#name').val();
        var email = $('input#email').val();
        var message = $('textarea#message').val();

        $.ajax({
            url: "/time",
            type: "POST",
            dataType: 'json',
            data: {
                name: name,
                email: email,
                message: message
            },
            success: function() {
                // Success message
                $('#success').html("<div class='alert alert-success'>");
                $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                $('#success > .alert-success')
                    .append("<strong>Your message has been sent. </strong>");
                $('#success > .alert-success')
                    .append('</div>');

                //clear all fields
                $('#contactForm').trigger("reset");
            },
            error: function() {
                // Fail message
                $('#success').html("<div class='alert alert-danger'>");
                $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                $('#success > .alert-danger').append('</div>');
                //clear all fields
                $('#contactForm').trigger("reset");
            }
        })

    }); 

}); 

推荐答案

尝试使用特定的文件名而不是文件夹.即;

Try a specific filename instead of a folder. ie;

url: "/time/index.html",

包括开发者控制台(浏览器中的F12)中的所有错误,以帮助我们为您提供帮助.

Include any errors from the Dev Console (F12 in Browser) to helps us help you.

这篇关于Ajax没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆