简体   繁体   English

这是我的 ajax 调用,但在此成功函数中不起作用

[英]This is my ajax call but in this success function not working

I am using a ajax call in my code.我在我的代码中使用了 ajax 调用。 But in this ajax call the success function not working.但是在这个 ajax 调用中,成功函数不起作用。

Below is the code I am using:下面是我正在使用的代码:

var data1 = { "name": namedata[0], "email": namedata[1], "mobile": namedata[2], "company": namedata[3], "message": namedata[4], };

$.ajax({
    type: "POST",
    url: url,
    data: data1,
    success: function (data) {
        alert("success");
        $('#myModalSuccess').css('display', 'block');

        $('.close').click(function () {
            $('#myModalSuccess').css('display', 'none');
        });

    },
    error: function () {
        $('#myModalFail').css('display', 'block');

        $('.close').click(function () {
            $('#myModalFail').css('display', 'none');
        });
    }
});

In error callback print the error in console.log() like below so that you will be able to identify the exact error-在错误回调中,在 console.log() 中打印错误,如下所示,以便您能够识别确切的错误 -

$.ajax({
type: "POST",
url: url,
data: data1,
success: function (data) {
    alert("success");
    $('#myModalSuccess').css('display', 'block');

    $('.close').click(function () {
        $('#myModalSuccess').css('display', 'none');
    });

},
error: function (err) {
console.log(err)

    $('#myModalFail').css('display', 'block');

    $('.close').click(function () {
        $('#myModalFail').css('display', 'none');
    });
}});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM