0

问题总结:

当下拉列表改变时,jQuery 触发 AJAX 来获取选定项目的 PM。项目中已有的 PM 数量在 PHP var$num_pms中。(在下面的 AJAX 中,这是作为第二个隐藏输入字段 #num_pms 的值插入的。)

在 AJAX 成功回调 fn 中,input#num_pms.val()读取并用于初始化一个计数器——但数字总是错误的。

为了排除故障,我试图从 读取该值input#num_pms,将其递增并将其重新写入input#test. 但是,提交表单后,test 的值为空。但是奇怪的是,值input#num_pms是正确的!

我必须做错事来读取input#num_pms字段值......?


HTML:下拉菜单触发 jQuery 运行 AJAX 搜索。结果放入#reportstable div。

Project*:<br />
<?php include 'inc/widgets/dropdown_all_projects.php';?>

<form action="" method="post" name="updatepm" enctype="multipart/form-data" id="TheForm">
    <div id="reportstable">
    </div>
</form>

阿贾克斯:

$project_num = $_POST['project_num'];
$project_id = get_project_id_from_project_num($project_num);

$aPMs = get_climgr_for_project($project_id,'user_id','first_name','last_name');
$num_pms = mysql_num_rows($aPMs);


//>Snippet< -- Inject following markup into #reportstable div.
echo
'<th width="50">
    Action
    <input type="hidden" name="project_id" value="'.$project_id.'">
    <input type="hidden" name="num_pms" id="num_pms" value="'.$num_pms.'">
    <input type="hidden" name="test" id="test" value="">
</th>
';

jQuery:触发 AJAX,将结果返回到#reportstable

$('#project_pick').change(function(e) {
    $('#project_pick').css('width', '500');
    $.ajax({
        type: "POST",
        url: "ajax/ax_all_ajax_fns.php", 
        data: "project_num=" + $(this).val(),
        success:function(data){
            $('#reportstable').html(data);

            //Tried adding this first
            var count = $('#num_pms').val() + 1;
            $('#test').val(count);

            //Tried this after above wouldn't work. It didn't either.
            //var count = 80;
        } //END success fn
    }); //END $.ajax()
}); //END dropdown .change() event
4

1 回答 1

1

尝试:

var count = parseInt($('#num_pms').val()) + 1;

还要确保#num_pmsDOM 中只有一个元素。

于 2013-04-24T20:37:35.313 回答