发送Ajax的数据PHP
问题描述:
我有我的网页上下面的jQuery代码:发送Ajax的数据PHP
现在我应该怎么放在location.php使数据到我的电子邮箱function ajaxFunction() {
$.ajax({
url:'location.php',
type:'POST',
data:'lat='+lat+'&long='+long,
success:function(d){
console.log(d);
},
error(w,t,f){
console.log(w+' '+t+' '+f);
}
});
}
?我是一个总noob和查找代码或教程将无法正常工作,因为我不明白它...
也可以让页面重定向到另一页,如果脚本完成? 我可以再补充:
window.location.href = "http://*.com";
或者我应该把更多的代码...我发现了互联网,因为我什么都不懂所有这些coeds,所以你能帮帮我吗?
答
您可以使用PHP中的mail()
函数发送电子邮件。
您还需要修复您的JS代码 - 除非您实际制作了lat
和long
全局变量,否则它们将不确定。
+0
好的,谢谢你,我知道我应该先做研究,但对我来说,这只是奇怪的代码,如果你说全局变量我不明白它......我不希望你更友好些,或者什么,我只是想让你明白这对我来说很难... – 2012-04-14 10:05:40
答
在你location.php,你可以做这样的事情,使由PHP脚本接收到的数据要到您的电子邮箱:上邮件
$messageBody = "lat: " . $_POST['lat'] . " long: " . $_POST['long'];
if (mail("[email protected]", "The Subject Line", $messageBody)) {
echo "success";
exit;
}
退房的链接了解更多信息()函数: http://php.net/manual/en/function.mail.php
重定向:
function ajaxFunction(lat, long) {
$.ajax({
url:'location.php',
type:'POST',
data:'lat='+lat+'&long='+long,
success:function(d){
// When the ajax call is successful, the redirection should happen here
window.location = "http://*.com";
},
error(w,t,f){
// this is when the ajax call fails
console.log(w+' '+t+' '+f);
}
});
}
你真的需要学习如何做你自己,而不是提出一些东西真的对一切** **这里。 – ThiefMaster 2012-04-14 09:59:00
好吧,你可以帮助我,然后我走了... – 2012-04-14 09:59:25
*给一个人一条鱼,你喂他一天。教一个人如何钓鱼,你一辈子喂他。* – ThiefMaster 2012-04-14 10:00:11