bonjours,
je suis apres une fonction de chargement avec ajax et json.
mon code appelle bien la template php avec les variables, cette template genere bien le html par contre il ne s'affiche pas dans la fonction succes.
voici mon code:
index avec la fonction load:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php
define ('ASSASSIN_ROOT', './');
$assassin_root = ASSASSIN_ROOT;
?>
<script type="text/javascript" src="<?php echo $assassin_root; ?>js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<?php echo $assassin_root; ?>js/jquery.json.js"></script>
<script>
function Load(query){
var json = $.JSON.encode(query);
var decode_json = $.JSON.decode(json);
$.ajax({
type: 'GET',
url:'Load_2.php',
data:{json: json},
success: function(html) {
$('#'+decode_json.id_div).html(html);
},
async: false
});
}
</script>
<div id="test">
</div>
<script>
var query = {id_div:'test',template:'test2.php',test:'ceci est un test'};
Load(query);
</script> |
voici le Load_2.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
function wrap_tpl ($data , $template) {
extract($data);
ob_start();
include $template;
$layout_content = ob_get_contents();
ob_end_clean();
return $layout_content;
}
if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
$data=array();
if($_GET['json']){
$json = $_GET['json'];
$data = json_decode($json, true);
echo wrap_tpl ($data , $data['template']);
}
}
?> |
et la template test2.php:
<?php echo $id_div."</br>".$template."</br>".$test;?>
j'ai bien ce retour dans firebug en reponse:
test</br>test2.php</br>ceci est un test
mais ma page reste blanche, le retour n'est pas injecter dans le div test.
si qqun peut m'aider merci d'avance.
Partager