jQuery Ajax允许进行多次调用

时间:2015-10-07 19:50:07

标签: jquery ajax

我正在创建一个单页面应用程序。我正在使用ajax来设置coldfusion会话变量。我无法使用jQuery调用多个ajax调用吗?

http://jsfiddle.net/1zka4soy/15/

如果单击打印标签按钮并输入一个数字,您将看到ajax调用及其在警报上设置的内容。 “新建”按钮设置完全相同,但由于某种原因无法运行。

这是一个只允许你运行一次的ajax规则吗?

由于某种原因,新按钮$('#addDealer').on('submit', function (e) {没有触发?

PrintLabel

$(document).ready(function () {
    // What happens when a user hits the "Accept" button on the dealer form
    $(".label_accept").click(function () {
        $('#LabelMaker').modal('hide');

    });

    $('#labelForm').on('submit', function (e) {
        e.preventDefault();
        //alert($(this).serialize());
        $.ajax({
            // the location of the CFC to run
            url: "proxy/LabelSession.cfm",
            // send a GET HTTP operation
            type: "post",
            // tell jQuery we're getting JSON back
            dataType: "json",
            // send the data to the CFC
            data: $('#labelForm').serialize(),
            // this gets the data returned on success
            success: function (data) {
                console.log(data);
                if (data !== "") {     
                    var link = "labels/DealerLabels.cfm";
                    window.open(link,'labelPDF'); 
                }
            }, 
            // this runs if an error
            error: function (xhr, textStatus, errorThrown) {
                // show error
                console.log(errorThrown);
            }
        });
    });
});

新按钮

$(document).ready(function () {
    // What happens when a user hits the "Accept" button on the dealer form
    $(".dealer_accept").click(function(){
        $('#NewDealer').modal('hide');

    });

    $('#addDealer').on('submit', function (e) {
        alert("working");
        e.preventDefault();
        alert($(this).serialize());
        $.ajax({
            // the location of the CFC to run
            url: "proxy/NewDealerSession.cfm",
            // send a GET HTTP operation
            type: "post",
            // tell jQuery we're getting JSON back
            dataType: "json",
            // send the data to the CFC
            data: $('#addDealer').serialize(),
            // this gets the data returned on success
            success: function (data) {
                console.log(data);
            }, 
            // this runs if an error
            error: function (xhr, textStatus, errorThrown) {
                // show error
                console.log(errorThrown);
            }
        });
    });
});

0 个答案:

没有答案