【发布时间】:2010-09-10 00:45:08
【问题描述】:
我对 ajax 还很陌生,我成功地将它应用到了 Drupal 站点。但我想知道,如何获取通过 ajax 加载部分内容的页面的 URL。这甚至可能吗? JSON 对象是在点击时检索的,那么在检索某个 URL 时如何使其工作? 我意识到这是一个非常广泛的问题,任何帮助将不胜感激。 提前致谢!
我的 JS 看起来像这样:
Drupal.behaviors.ajax_pages = function (context) {
$('a.categoryLink:not(.categoryLink-processed)', context).click(function () {
var updateProducts = function(data) {
// The data parameter is a JSON object. The films property is the list of films items that was returned from the server response to the ajax request.
if (data.films != undefined) {
$('.region-sidebar-second .section').hide().html(data.films).fadeIn();
}
if (data.more != undefined) {
$('#content .section').hide().html(data.more).fadeIn();
}
}
$.ajax({
type: 'POST',
url: this.href, // Which url should be handle the ajax request. This is the url defined in the <a> html tag
success: updateProducts, // The js function that will be called upon success request
dataType: 'json', //define the type of data that is going to get back from the server
data: 'js=1' //Pass a key/value pair
});
return false; // return false so the navigation stops here and not continue to the page in the link
}).addClass('categoryLink-processed');
}
【问题讨论】:
标签: php javascript jquery ajax drupal