weixin_33694620 2015-10-13 22:03 采纳率: 0%
浏览 3

调试jQuery处理程序

This question is a followup of this one. I have created a simple example to check how code is executed within the handler. For the form

<form id="calendar_id" method="post">
    Insert date: <input id="date_id" type="text" name="l_date" required>
</form>

I'm trying to retrieve the fields using the following javascript:

function get_form_data_uid($form) {
    var unindexed_array = $form.serializeArray();
    var indexed_array = {};

    $.map(unindexed_array, function (n, i) {
        indexed_array[n['name']] = n['value'];
    });

    indexed_array['uid'] = 'badbfadbbfi';

    return indexed_array;
}

$("#calendar_id").submit(function (e) {
    var uri, method, formId, $form, form_data;
    // Prevent default submit
    e.preventDefault();
    e.stopImmediatePropagation();

    uri = "/";
    method = "POST";
    formId = "#calendar_id";

    $form = $(formId);
    form_data = get_form_data_uid($form);

    alert("form_data " + form_data);

    // Set-up ajax call
    var request = {
        url: uri,
        type: method,
        contentType: "application/json",
        accepts: "application/json",
        cache: false,
        // Setting async to false to give enough time to initialize the local storage with the "token" key
        async: false,
        dataType: "json",
        data: form_data
    };
    // Make the request
    $.ajax(request).done(function (data) { // Handle the response
        // Attributes are retrieved as object.attribute_name
        console.log("Data from change password from server: " + data);
        alert(data.message);
    }).fail(function (jqXHR, textStatus, errorThrown) { // Handle failure
        console.log(JSON.stringify(jqXHR));
        console.log("AJAX error on changing password: " + textStatus + ' : ' + errorThrown);
    });

});

However, the code within the handler is not executed (the alert is not shown). Why?

Edit:

The code works jsfiddle but not in firefox.

  • 写回答

1条回答 默认 最新

  • weixin_33716154 2015-10-13 22:22
    关注

    At least, you are calling a function get_form_data_with_token() which is not defined anywhere in your posted code. Perhaps you meant to call your get_form_data_uid().

    Would have just made this a comment, but apparently cannot.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c