dqwh1119 2016-05-16 08:44
浏览 108

如何从特定页面中提取php变量值

I have 2 pages, index.html and dataLoad.php. On page load, dataLoad.php loads all data for the current date and index.html displays this data on a table.

<?php include 'dataLoad.php'; ?>

On button click, a function is called that contains an AJAX that is sent to change the date variable for dataLoad.php so it loads all the data for another day and this information is stored in variables. Now I want to echo the new data values into my html using something like

document.getElementById("hour1").innerHTML = "<?php echo $hour1 ?>";

But even though the page is included, it can not import the new data (it is empty). Is there a a way to import data from the page with the new values?

Thank you for any help!

  • 写回答

2条回答 默认 最新

  • doukai1226 2016-05-16 09:03
    关注

    Use ajax to load your new data (https://api.jquery.com/jquery.post/) like so:

    $.post("dataLoad.php", {newId:$yourNewId}, function(data){ $("#hour1").html(data); });

    You'll need a function in your php that executes when it gets $_POST['newId'] and have it return only the html you want to place in #hour1

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题