weixin_33675507 2018-07-17 07:58 采纳率: 0%
浏览 22

选择值不显示

i have a webpage that gets data from a local database. i can retrieve the data to be displayed but for some reason a certain value (value of '#item_name') does not display. it's supposed to be the text inside a select dropdown with an id of item_name. am i missing something? here is my code:

$.ajax({
    url: '/get_items',
    method: 'POST',
    data: { item_id: item_id },
    success: function (response) {
        alert(JSON.stringify(response.result[0].name));
        $('#hidden_item_item_id').val(response.result[0].id);
        $('#item_name').val(response.result[0].name);
        $('#item_remarks').val(response.result[0].remarks);
        $('#updateItemsModal').modal('show');
    }
});
  • 写回答

2条回答 默认 最新

  • weixin_33694172 2018-07-17 08:05
    关注

    You don't need to do JSON.stringify, just add dataType : 'json' in ajax request.

    $.ajax({
        url: '/get_items',
        method: 'POST',
        data: { item_id: item_id },
        dataType: 'json',
        success: function (response) {
            alert(response.result[0].name);
            $('#hidden_item_item_id').val(response.result[0].id);
            $('#item_name').val(response.result[0].name);
            $('#item_remarks').val(response.result[0].remarks);
            $('#updateItemsModal').modal('show');
        }
    });
    

    Please try

    评论

报告相同问题?