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 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上