0

单击按钮时执行 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);
    })
}

“d_more_hotels”函数中的 jQuery.ajax 函数在 url 中给出 404 错误,但文件存在。

我检查了所有变量并记录日志以查看使用的完整 url 参数,但一切似乎都很好。

在 WordPress 最新版本框架下工作。

:S

任何帮助都将不胜感激。

编辑:

在这里找到解决方案https://stackoverflow.com/a/3445620/3676282

WordPress功能混乱

4

2 回答 2

0

试试这个方法

  url: theme.child_theme_uri+'/searcher.php',
  type: 'GET',
  data: {"t":t, "l":l, "c":c, "w":w} ,
于 2016-07-18T13:26:33.960 回答
0

在这里找到解决方案https://stackoverflow.com/a/3445620/3676282

由于 Wordpress 安全性而引发 404 错误

于 2017-07-25T19:04:17.717 回答