du7979 2016-01-19 21:43
浏览 42
已采纳

html表单字段在提交表单之前从sql数据库获取内容?

I try to get content from database before submitting the form.I call javascript function in onload method.When I Directly write php code into textarea it works but when I append same php content to textarea through JS its not working, total php content only shown in textarea.Thanks in advance.

var parent=document.getElementById("textarea");
var child=document.createTextNode(' <?php '+
' include "conn.php"; '+
' $q1="SELECT `breakfast` FROM `foodmenu` WHERE `day`=\'Wednesday\'"; '+
' $result=$conn->query($q1); '+
' while($row=$result->fetch_assoc()) '+
' { '+
' echo $row["breakfast"]; '+
' } '+
' ?> ');
parent.appendChild(child);

For your easy reference

  • 写回答

1条回答 默认 最新

  • drfb52000 2016-02-24 22:40
    关注

    call this method while load page, the field content get load from sql database. getmenu.php file have business logic to get query

    $("select").on('change',function(){
    
        $.ajax({
            type: "POST",
            url: "getmenu.php",
            data: {
                day: $("#showday").val()  ,
                forwhat: $("#tab .active a").text()
            },
            success: function (Response) {
                $("#menu").val(Response.trim());
            } // you had an extra );
        });
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码