dongli5785 2014-07-18 18:56
浏览 35
已采纳

输入数据并从jquery事件运行php脚本

I am having a problem getting data from jquery into a php script. I am trying to load a php script (i.e. send an email) with a variable (email address) from jquery event without leaving the original page and going to a confirmation page. Please help!

Here is my jquery code:

<script>
  $("#test").click(function() { 
    var id = 1;
    $("#target").load("javascript_test2.php", id);

  });
</script>
<div id="target">hmmm did it work?</div>
</body>

This is the php I would like to receive and process the code:

<div id="S1">
<?php 
$id = htmlspecialchars($_POST['id']);

for ($i=1; $i<=2; $i++) {
echo $id . 'Hello world ' . $i . '<br>'; 
}

require_once('lawyeralertemail.php');

?>
</div>

Thanks!

  • 写回答

1条回答 默认 最新

  • doukezi4576 2014-07-18 19:02
    关注

    You can use jQuery ajax to post data into your PHP. Here is a link: http://api.jquery.com/jquery.post/

    This will allow you to post data without reloading the page and give your user a better experience.

    You can then use $_POST to capture the data inside your PHP.

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

报告相同问题?

悬赏问题

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