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

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?