[PHP-JS] Récupération de variable php en javascript
Bonjour,
j'ai créé une table tb_type et sur j'ai une query.php qui contient ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
<?php
....//connection base
$sql_prix = "SELECT * FROM tb_type";
$res_prix = mysql_query($sql_prix);
$tab_prix =array();
while($prix_pub = mysql_fetch_assoc($res_prix)){
prix = $prix_pub['tarif_type'];
array_push($tab_prix, $prix);
}
?> |
ensuite je crée la function pour instancier l'objet, puis la function pour récupérer les prix et on m' conseillé ceci mais j'ai pa très bien compris :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
function prix() {
xhr = getXhr (); //getXhr(); function instanciation objet créer auparavant
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
return xhr.responseText;
}
}
xhr.open("GET","query.php?action=prix", false);
xhr.send(null);
} |
et en POST c'est pas mieux ?
comment récupérer $tab_prix[0], $tab_prix[1], $tab_prix[2], $tab_prix[3],
? en js genre var prix_U = $tab_prix[0]...prix_D=$tab_prix[1]