Response title
This is preview!
Hi there.
In my code I call a function which first of all displays a form and builds the select drop-down lists with the appropriate options. I then call the following function, passing it a case id. The function:
1. calls another file that uses AJAX to connect to my database and returns a single row of data for the case id specified.
2. checks if the ajax function has completed successfully
3. if successful, it populates the form fields with the json data
This form is correctly populated but if I remove the alert code then it does not populate the form. Can anybody help?function loadCase (caseID) { $.get("./case_det/exist_case_det/ajax_get_exist_case_det.php?caseID=" + caseID, function(data, status) { alert (caseID + " now loading"); if (status === "success") { json_data=JSON.parse(data); //save object to localStorage localStorage['my_case'] = JSON.stringify(json_data); // Populate Case Detail $('#categorisation').val(json_data[0].cat_id); $('#priority').val(json_data[0].priority_id); $('#type').val(json_data[0].type_id); $('#stage').val(json_data[0].stage_id); $('#summary').val(json_data[0].summary); } else { alert ("System encountered probl;ems laodign case data"); } }); }
I've also tried the following code but if I omit the alert then it doesn't work.
function loadCase (caseID) { $.ajax({ url : './case_det/exist_case_det/ajax_get_exist_case_det.php', type: 'POST', data: {caseID:caseID}, success : loadCaseSuccess, error: loadCaseError }); } //loadCase().done(loadCaseSuccess); function loadCaseSuccess(data, textStatus) { alert(textStatus); json_data=JSON.parse(data); alert(json_data[0].cat_id); // // Populate Case Detail $('#categorisation').val(json_data[0].cat_id); } function loadCaseError() { alert ("System encountered problems loading case data"); }
And I've tried setting async:false but that didn't help.
Please can you let me know where I am going wrong. Many thanks
© 2013 jQuery Foundation
Sponsored by and others.