douding6266 2013-11-08 16:37
浏览 16

加载JSON和绑定到表单字段不一致

So I have a datagrid where when a row is clicked a form is loaded, then JSON data is pulled and propagates form fields using JQuery. It works great...sometimes. It is very inconsistent, and I can't figure out why it doesn't work every time. I can click on a row, it loads, then (without refreshing) the next few times it might not, and then (still without refreshing) the next few random number of times it does.

Any help would be appreciated. The first thing the script does is load the corresponding form into the div #dlg, then pull the JSON data, and then parse and populate the fields.

function fw_getFormData(r_id, t_name, r_key){   
    $('#dlg').dialog('refresh', 'dg_process/dg_edit_form.php?table='+t_name),
    jsonURL = 'form_data/dg_forms_data.php?table='+t_name+'&pkey='+r_key+'&id='+r_id;

    var jqxhr = $.getJSON( jsonURL, function() {})

        //JSON load is complete. Propagate form fields.
        .done(function(data) {
            $.each(data, function(index, obj) {  
                $.each(obj, function(key, value) {
                    //$('#'+key).attr("value", value);
                    $("#dlg").parents("div").find('input[name='+key.toLowerCase()+']').val(value);
                 }); //End inner parse of JSON
             }); //End outer Parse
         })  // End .done

        //JSON Did not load
            .fail(function() {
                 alert( "JSON could not load" );
            }) // End .fail
});

The JSON it is parsing looks like this:

[{"staffID":"1","fname":"Bill","lname":"Smith","email_address":"bsmith@fakeemail.net","password":"testpw"}]

As a final note, the alert for .fail never fires when it doesn't work.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大