除非我在代码中包含警报,否则不会使用AJAX填充表单字段 [英] Form fields not populated from AJAX unless I include an alert in the code

查看:65
本文介绍了除非我在代码中包含警报,否则不会使用AJAX填充表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我调用一个函数,该函数首先显示一个表单,并使用适当的选项构建选择下拉列表.然后,我调用以下函数,并向其传递一个案例ID.功能:

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. 调用另一个使用AJAX连接到我的数据库的文件,并为指定的案例ID返回一行数据.

  1. calls another file that uses AJAX to connect to my database and returns a single row of data for the case id specified.

检查ajax功能是否已成功完成

checks if the ajax function has completed successfully

如果成功,它将使用json数据填充表单字段

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");
    }

});
}

推荐答案

尝试使用最新的jqXHR方法...

Try doing it with the more recent jqXHR methods...

function loadCase (caseID) {

    $.get("./case_det/exist_case_det/ajax_get_exist_case_det.php?caseID=" + caseID )
    .done( function( data ) {

        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);

    })
    .fail( function() {
        alert ("System encountered problems loading case data");
    });
}

这篇关于除非我在代码中包含警报,否则不会使用AJAX填充表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆