单击按钮正常时执行ajax请求,按预期返回。但问题是当我尝试将一个函数绑定到一个带有ajax请求的元素时。
该函数在此url上给出了404错误,但文件存在(同一服务器,同一域...)
jQuery(function() {
jQuery('.searcher-rooms .button').click(function() {
var n = jQuery.now(),
l = jQuery('.town-list').val(),
c = jQuery('.short-hotel-list').val();
if (l == null) {
l = 'all';
};
if (c == null) {
c = 'all-hotels';
};
if (l != '' && l != 'all' && l != 'current') {
n += '&l='+l;
};
if (c != '' && c != 'all-hotels') {
n += '&c='+c;
};
jQuery.ajax({
url: theme.child_theme_uri+'/searcher.php?t='+n,
type: 'GET',
beforeSend: function() {
jQuery('#data-wrapper').addClass('loading');
}
}).done(function(data) {
jQuery('#data-wrapper').html(data).attr('data-time', n.toString().split('&')[0]).attr('data-location', l).attr('data-hotel', c);
jQuery('#data-wrapper').removeClass('loading');
jQuery('.load-more-hotels').bind('click', d_more_hotels);
})
})
});
function d_more_hotels() {
var e = jQuery('#data-wrapper'),
t = e.attr('data-time'),
l = e.attr('data-location'),
c = e.attr('data-hotel'),
w = jQuery('.load-more-hotels').attr('data-page');
jQuery.ajax({
url: theme.child_theme_uri+'/searcher.php?t='+t+'&l='+l+'&c='+c+'&w='+w,
type: 'GET',
beforeSend: function() {
jQuery('#data-wrapper').addClass('loading');
}
}).done(function(data) {
jQuery('#data-wrapper').html(data)
jQuery('#data-wrapper').removeClass('loading');
jQuery('.load-more-hotels').attr('data-page', parseInt(w)+1).unbind().bind('click', d_more_hotels);
})
}
jQuery.ajax函数内部" d_more_hotels"函数在url中给出404错误,但该文件存在。
我已经检查了所有变量并做了一个日志来查看使用的完整网址参数,但一切似乎都没问题。
在WordPress最新版本框架下工作。
:S
任何帮助都是相关的。
编辑:
此处找到解决方案https://stackoverflow.com/a/3445620/3676282
WordPress功能混乱
答案 0 :(得分:0)
试试这种方式,
{{1}}
答案 1 :(得分:0)
此处找到解决方案https://stackoverflow.com/a/3445620/3676282
由于Wordpress安全性而触发了404错误