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.