我的页面上有以下jQuery代码:
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);
}
});
}现在,我应该在location.php中放入什么内容才能将数据发送到我的电子邮箱?我完全是个菜鸟,查代码或教程是行不通的,因为我不懂……
另外,如果脚本已经完成,我可以让页面重定向到另一个页面吗?我能不能补充一下:
window.location.href = "http://stackoverflow.com";或者我应该放更多代码..。我在网上找到了所有这些女孩子,因为我什么都不懂,所以你能帮我吗?
发布于 2012-04-14 19:26:38
在你的location.php中,你可以这样做,让php脚本接收到的数据进入你的邮箱:
$messageBody = "lat: " . $_POST['lat'] . " long: " . $_POST['long'];
if (mail("youremail@domain.com", "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://stackoverflow.com";
},
error(w,t,f){
// this is when the ajax call fails
console.log(w+' '+t+' '+f);
}
});
}发布于 2012-04-14 18:02:36
您可以使用PHP中的mail()函数来发送电子邮件。
你还需要修复你的JS代码--除非你真的创建了lat和long全局变量,否则它们将是未定义的。
https://stackoverflow.com/questions/10152685
复制相似问题