dtvx3420 2017-11-13 17:59
浏览 52
已采纳

如何在值输入html中加载数据网站

I am having this piece of code, to load data form PHP in hosting. Then I am displaying received data to value input :

$("#MerekDagang").load("http://jiyo-hotel.com/bpom/data.php?id=1&act=Get_MerekDagang").value;

The question is how to load data and insert as a input value here:

<input type='text' class='form-control' name='Merek_Dagang' placeholder='Merek Dagang' id='MerekDagang' value=''>
  • 写回答

1条回答 默认 最新

  • dongmi6102 2017-11-13 18:06
    关注

    That's not the right way to use the .load method in jquery. It's trying to load the data result into that element tag (which is not a wrapping element, it's a singular input element).

    You should use this instead:

    $(document).ready(function(){
        $.get("http://jiyo-hotel.com/bpom/data.php?id=1&act=Get_MerekDagang",function(data){
            $("#MerekDagang").val(data);
        });
    });
    

    This explicitly tells where that data should go (into the val of the element selected).

    P.S.: I'm not sure why you would want to immediately load data in through ajax like this though... seems inefficient, where you could have put that data in during the php output build.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计