404 error when binding named function with jQuery ajax inside

Samuel E. Cerezo

Doing an ajax request when click button works fine, return as expected. But the problem is when I try to bind a function to an element with an ajax request inside.

The function give me 404 error on this url, but the file exist (same server, same domain...)

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 function inside "d_more_hotels" function give a 404 error in url, but the file exists.

I've checked all variables and doing a log to see full url param used, but all seems ok.

Working under WordPress last version framework.

:S

Any help is apreciated.

EDIT:

Solution found here https://stackoverflow.com/a/3445620/3676282

WordPress function mess

Samuel E. Cerezo

Solution found here https://stackoverflow.com/a/3445620/3676282

404 error fired due to Wordpress security

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Ajax - Handle 404 error in jquery $.when

jQuery ajax returning 404 error when passing URL as post data

Proper binding of $(this) when extracting named function in .on() callback

Error in handling json data inside jquery ajax each function

jQuery Ajax Unexpected token < error on 404 instead of normal ajax error handler function

binding of this when calling a function inside a function

Jquery ajax call inside a then function

JQuery/AJAX & PHP - Error with isset() when using .load() function

jQuery Ajax request with error 404 (not found) but it works

Jquery ajax is giving me a 404 not found error

Jquery, Ajax Error 404 with Webmethod url

Getting 404 error when calling ajax in WordPress

jQuery detect ajax finish inside change function

Jquery ajax call inside success function

Get variable by ajax inside a function (Jquery)

When binding a event to two functions and unbinding it inside one function

systemd service permission error when binding to ipc port inside a VM

ajax call inside ajax success jquery then ajaxstart function not working

JQuery/Ajax/Class: removeClass() then addClass() is not working as intended inside ajax function

Django 404 error when loading <img> tag inside template

Spring Boot + Bootstrap + jQuery : Error 404 in $ajax call on Firefox

jQuery AJAX - Redirect to 404 page when load method fails

Twig Extended Function error when inside the loop

Error when using dplyr {{ }} with aggregate inside a function

Error when using dplyr inside of a function

Variable undeclared error when used inside a function

there was an error in php when the function was placed inside while

Receiving an error when using aov() inside a function

Evaluate jquery selector in named callback function only when callback is called