2016-05-16 26 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(); 
} 

だから私は何ができるか、私はdescription.phpでMySQLの変数を使用することができますか?

ありがとうございました!

+0

このようなものを使用することができ、あなたは申し訳ありません、それは間違いだったevent_description' –

+0

'kalendar_description'とバインド'としての機能を命名します。私のスクリプトでは正しかった、それは他の言語でちょうどすべてだったので、私は間違いを翻訳しました:) –

答えて

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

@ダングリーンあなたを助けてくれることを歓迎します...;)あなたが本当に役に立ったら、私の答えを投票してください.. Thankx .. –

関連する問題