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 );
        });
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题