By WorldFallz on
I'm struggling with refreshing a view after an editablefield field has been updated (changing the value of the field triggers a series of actions that update other parts of the view).
I'm trying to combine jaypan's awesome tutorial along with the ajax_views.js code directly from views, but the view is not refreshing.
Here's what I have so far:
(function($) {
$(document).ajaxComplete(function(e, xhr, settings) {
if (settings.url.substr(settings.url.length - 21) == "editablefields_submit") {
var ajaxPath = Drupal.settings.views.ajax_path;
if (ajaxPath.constructor.toString().indexOf("Array") != -1) {
ajaxPath = ajaxPath[0];
}
$.each(Drupal.settings.views.ajaxViews, function(i, settings) {
var view = '.view-dom-id-' + settings.view_dom_id;
if (!$(view).size()) {
view = '.view-id-' + settings.view_name + '.view-display-id-' + settings.view_display_id;
}
$(view).filter(function() {
return !$(this).parents('.view').size();
})
.each(function() {
var target = this;
alert("reached ajax call");
$.ajax({
url: ajax_path,
type: 'GET',
data: settings,
success: function(response) {
if (response.__callbacks) {
$.each(response.__callbacks, function(i, callback) {
eval(callback)(target, response);
});
}
},
error: function() { alert(Drupal.t("An error occurred at @path.", {'@path': ajax_path})); },
dataType: 'json'
});
});
});
}
});
}(jQuery));
The code executes without error and the alert pops up as expected, but the view just doesn't refresh.
Any pointers/info would be greatly appreciated.
Comments
_
wow-- it never fails, as soon as I posted I found a stupid typo. Originally, I didn't think that was it but it was (I just hadn't refreshed the cache).
Changing the ajax_path to ajaxPath fixes it. For completeness, here's the corrected code:
Thank you for great script.
Thank you for great script. It works perfectly for Drupal 6