2016-05-16 124 views
0

我目前正在处理日历。在日历旁边,我想要一个描述框,其中当用户单击日历中的日期时,应该显示有关该事件的更多信息。通过AJAX传输变量

我直到现在: HTML/PHP:

// Variables from MySQL request:  
$event 
$date 
$place 
$start 
$end 

<button type="button" onclick="event_description()">$day</button> 

<div id="details"></div> 

AJAX:

function event_description() { 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
     document.getElementById("details").innerHTML = xhttp.responseText; 
    } 
    }; 
    xhttp.open("GET", "kalender/description.php", true); 
    xhttp.send(); 
} 

所以我能做些什么,所以我可以使用MySQL变量在description.php?

感谢您的帮助!

+0

你被点名功能'kalendar_description'和绑定'event_description' –

+0

对不起,这是一个错误。在我的脚本中是正确的,它只是在其他语言,所以我犯了一个错误翻译:) –

回答

0

您可以使用这样的事情..

// 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> 

Script代码

<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> 
+0

你帮了我很多!谢谢! –

+0

@DanGreen不客气,很高兴帮助你...;)为我的答案投票,如果它真的对你有帮助.. Thankx .. –