这是我的代码: 在A函数中:
var daaa=document.getElementById('da').value= year+ "-" +month+ "-" +day;
document.form1.bookingsession.focus();
var coords = {
"lat": daaa
};
$.get('bs.php', coords, function () {
alert('data sent');
});
我的php代码是:
<?php
$output = isset($_GET['lat']) ? $_GET['lat'] : 0;
print("$output");
?>
当我打印$ output时,我得到的值为0,但实际上必须得到变量daaa上的值。让我知道我犯了哪些错误.... 提前谢谢
答案 0 :(得分:0)
更改此
var coords = {
"lat": daaa
};
到
var coords = {
lat: daaa
};
你错放了双引号。
http://api.jquery.com/jQuery.get/
来自jquery的例子
//$.get("test.php", { name: "John", time: "2pm" } );
答案 1 :(得分:0)
尝试更改
var daaa=document.getElementById('da').value= year+ "-" +month+ "-" +day;
到
var daaa=document.getElementById('da').value + "-" + year+ "-" +month+ "-" +day;
无论如何在这种情况下你应该检查你的“头号”动作是否真的在客户端设置了变量。你可以通过alert(daaa)或console.log(daaa);
来完成答案 2 :(得分:0)
首先提到@coramba提到的行动,
然后修改你的javascript代码:
$.get('bs.php', coords, function (dataThatPhpPrints) {
alert(dataThatPhpPrints);
});
..你会看到它实际上返回了你发送给PHP脚本的值,PHP脚本返回了它的打印。
为了确保您自己的脚本能够输出修改PHP代码的内容,如下所示:
<?php
$output = isset($_GET['lat']) ? $_GET['lat'] : 0;
print("$output - is response from the PHP!!!");
?>
现在,当您运行yor javascript时,您将收到类似
的警告消息ActualValueOfLATYouSentToPHP - is response from the PHP!!!
请记住,如果你想测试你的PHP是否有效,你只能在浏览器中打开它并等待一些魔法发生,因为它使用$ _GET来获得一些值,这意味着你需要提供它作为QueryString,键为'lat':
yourhost/bs.php?lat=someTestValue