我有一个问题,从jquery到php脚本的数据。我试图加载一个php脚本(即发送电子邮件)与变量(电子邮件地址)从jquery事件不离开原始页面,并前往确认页面。请帮助!
这是我的jquery代码:<script>
$("#test").click(function() {
var id = 1;
$("#target").load("javascript_test2.php", id);
});
</script>
<div id="target">hmmm did it work?</div>
</body>
这是我要接收和处理的php代码:
<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>
谢谢!
可以使用jQuery ajax将数据发布到PHP中。这里有一个链接:http://api.jquery.com/jquery.post/
这将允许您在不重新加载页面的情况下发布数据,并为您的用户提供更好的体验。
然后可以使用$_POST来捕获PHP中的数据