将命名函数与内部 jQuery ajax 绑定时出现 404 错误
404 error when binding named function with jQuery ajax inside
当点击按钮工作正常时执行 ajax 请求,return 符合预期。但问题是当我尝试将一个函数绑定到一个内部有 ajax 请求的元素时。
这个函数给我 404 错误 url,但是文件存在(相同的服务器,相同的域...)
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 函数 inside "d_more_hotels" 函数在 url 中给出 404 错误,但文件存在。
我检查了所有变量并记录日志以查看使用的完整 url 参数,但一切似乎都正常。
在 WordPress 最新版本框架下工作。
:S
感谢任何帮助。
编辑:
在此处找到解决方案
WordPress 功能混乱
试试这个方法,
url: theme.child_theme_uri+'/searcher.php',
type: 'GET',
data: {"t":t, "l":l, "c":c, "w":w} ,
在此处找到解决方案
404 错误因 Wordpress 安全性而引发
当点击按钮工作正常时执行 ajax 请求,return 符合预期。但问题是当我尝试将一个函数绑定到一个内部有 ajax 请求的元素时。
这个函数给我 404 错误 url,但是文件存在(相同的服务器,相同的域...)
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 函数 inside "d_more_hotels" 函数在 url 中给出 404 错误,但文件存在。
我检查了所有变量并记录日志以查看使用的完整 url 参数,但一切似乎都正常。
在 WordPress 最新版本框架下工作。
:S
感谢任何帮助。
编辑:
在此处找到解决方案
WordPress 功能混乱
试试这个方法,
url: theme.child_theme_uri+'/searcher.php',
type: 'GET',
data: {"t":t, "l":l, "c":c, "w":w} ,
在此处找到解决方案
404 错误因 Wordpress 安全性而引发