Javascript 通过AJAX传输变量
我现在正在做日历。在日历旁边,我想有一个描述框,当用户单击日历中的日期时,应该在其中显示有关事件的更多信息 到目前为止我所拥有的: HTML/PHP:Javascript 通过AJAX传输变量,javascript,php,html,ajax,variables,Javascript,Php,Html,Ajax,Variables,我现在正在做日历。在日历旁边,我想有一个描述框,当用户单击日历中的日期时,应该在其中显示有关事件的更多信息 到目前为止我所拥有的: HTML/PHP: // Variables from MySQL request: $event $date $place $start $end <button type="button" onclick="event_description()">$day</button> <div id="details">&
// Variables from MySQL request:
$event
$date
$place
$start
$end
<button type="button" onclick="event_description()">$day</button>
<div id="details"></div>
那么我该怎么做才能使用description.php中的MySQL变量呢
谢谢你的帮助 你可以用这样的东西
// Variables from MySQL request:
$event
$date
$place
///pass all the parameters in onclick function as arguments
<button type="button" onclick="event_description('<?php echo $event ?>','<?php echo $date ?>','<?php echo $place ?>')">$day</button>
<div id="details"></div>
//MySQL请求中的变量:
$event
$date
$place
///将onclick函数中的所有参数作为参数传递
你可以用这样的东西
// Variables from MySQL request:
$event
$date
$place
///pass all the parameters in onclick function as arguments
<button type="button" onclick="event_description('<?php echo $event ?>','<?php echo $date ?>','<?php echo $place ?>')">$day</button>
<div id="details"></div>
//MySQL请求中的变量:
$event
$date
$place
///将onclick函数中的所有参数作为参数传递
您将函数命名为kalendar\u description
和bindevent\u description
抱歉,这是一个错误。在我的脚本中,它是正确的,只是用了另一种语言,所以我翻译它时犯了一个错误:)您将函数命名为kalendar\u description
和bindevent\u description
抱歉,这是一个错误。在我的脚本中,它是正确的,只是用了另一种语言,所以我在翻译它时犯了一个错误:)@DanGreen不客气,很高兴帮助你……;)如果我的答案真的对你有帮助,请投票表决。。谢谢。@DanGreen不客气,很高兴能帮助你……;)如果我的答案真的对你有帮助,请投票表决。。谢谢。。
<script>
///get all the params here in function
function event_description(event_name,date,place) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("details").innerHTML = xhttp.responseText;
}
};
/////create a string of all the parameters and pass this with requested url as query string and get all these params in target file using `$_GET[]`
var params = 'event_name='+event_name+'&date='+date+'&place='+place;
xhttp.open("GET", "kalender/description.php?"+params, true);
xhttp.send();
}
</script>