Submitted by neoziox on
Voici mon code pour ajax_results_adherents.module :
<?php
function ajax_results_adherents_init() {
drupal_add_js('misc/jquery.form.js');
drupal_add_library('system', 'drupal.ajax');
}
/**
* Implements hook_menu().
*/
function ajax_results_adherents_menu() {
// A menu callback is required when using ajax outside of the Form API.
$items['adherents'] = array(
'page callback' => 'ajax_link_response',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function
ajax_link_response($tid, $nid = 0, $cat, $type = 'ajax', $adNom) {
$output = _ajax_results_adherents_load_noder($nid);
if ($type == 'ajax') {
$commands = array();
$commands[] = ajax_command_replace('#block-views-apercu-de-la-fiche-block', $output);
$page = array(
'#type' => 'ajax',
'#commands' => $commands
);
ajax_deliver($page);
}
else {
return $output;
}
}
function
_ajax_results_adherents_load_noder($nid = 0) {
return views_embed_view ('apercu_de_la_fiche','block', $nid);
}
?>
Sur ma page je mets ce lien :
<a href="/en/adherents/87/40/85/nojs/il-veneziano" class="use-ajax">Il Veneziano</a>
Malheureusement j'ai ce message quand je clique sur le lien :
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /en/adherents/87/40/85/ajax/il-veneziano
StatusText: OK
ResponseText:
<i>Bla bla bla de ma page</i>
Quel est le problème ?
Il vous manque un 'page
Permalien Soumis par hles le 9 Juillet, 2012 - 20:07
Il vous manque un
'page arguments' => array(2, 3, ...)
pour récupérer les arguments dans votre URL.Pas obligatoire d’après ce
Permalien Soumis par neoziox le 9 Juillet, 2012 - 22:35
Pas obligatoire d'après ce que je lis ici
Grâce à
'page callback' => 'ajax_link_response'
puis àfunction ajax_link_response($tid, $nid = 0
.De plus, j'ai essayé et j'obtiens le même résultat.
PS Je n'ai pas besoin de vider le cache de Drupal je pense
J’ai une autre piste. En fait
Permalien Soumis par neoziox le 11 Juillet, 2012 - 07:49
J'ai une autre piste. En fait j'ai exactement le même message si je désactive le module. Où est le problème ?
Si la solution Ajax «made in
Permalien Soumis par neoziox le 13 Juillet, 2012 - 14:46
Si la solution Ajax "made in Drupal" ne fonctionne pas, je fais la mienne.
Je crée un Javascript:
<?php
// ***** ATTENTION ***** Je mets <?php uniquement pour coloriser la syntaxe
(function ($) {
$(document).ready(function(){
$(".ajax").each(function(i, el){
$(el).click(function(e){
e.preventDefault();
var hrefAjax = $(this).attr("href");
var nid = hrefAjax.split('/')[4];
$.ajax({
type: "GET",
url: "/sites/all/themes/omega/omega/includes/ajax_adherents.php",
data: "nid="+nid,
beforeSend: function() {
$(el).after('<div class="ajax-progress ajax-progress-throbber"><div class="throbber"></div></div>');
},
success: function(retour) {
$('.ajax-progress').remove();
$('.view-apercu-de-la-fiche').empty().append(retour);
}
});
return false;
});
});
});
}(jQuery));
?>
Voici mon fichier
ajax_adherents.php
:<?php
$nid = $_GET['nid'];
//set the working directory
chdir('/home/www/web/');
define('DRUPAL_ROOT', getcwd());
//Load Drupal
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//Je récupère ma vue
$view = views_get_view('apercu_de_la_fiche');
$arrayView = $view->execute_display('block', array($nid));
//Je dois modifier les liens présent dans ma vue
$theView = preg_replace('#/sites/all/themes/omega/omega/includes#', '', $arrayView['content']);
//J'affiche ma vue
print($theView);
?>
Enfin, j'ajoute
class="ajax"
aux liens concernés.