Monday, November 19, 2012

Re: Bad Request "URL not found" - after an JQuery change event

have you checked the CSRF setting in the security component? - you would not be the first one to be tripped-up by the Form helper security token regimen when trying to use ajax forms.

On Friday, November 16, 2012 1:53:13 AM UTC-5, Benjamin Such wrote:
Hey guys, I am really stuck with that problem. I have a JQuery Dialog which contains a selectbox. When I change the option inside this selectbox, another selectbox shows up with options generated from an .ajax() event. Anyway... everything works fine, but when I submit the form CakePHP says: 404 Bad Request - URL was not found, but it DOES EXISTS 100%. I tested it several times to be sure, but another thing is: When submit the form WITHOUT selecting any option from the first selectbox the form is submitted correctly. I dont know what to post really but here is my Javascript:

$('select[data-onchange=true]').live("change", function() {
       
        var _this = $(this);
        var element = $('select[data-onchange-trigger=' + _this.attr("id") + ']:first');
       
        if (typeof element == "object") {
            if (_this.attr("data-onchange-load")) {
                var options = element.prop("options");
                var load = _this.attr("data-onchange-load");
                $.ajax({
                    dataType: "json",
                    url: load + _this.find('option:selected').val(),
                    beforeSend: function() {
                        $('.ajax-loader').show();
                        element.find('option').remove();
                        element.parent().hide();
                    },
                    success: function(data) {
                        $.each(data, function(index, _data) {
                            if (typeof _data == "object") {
                                $.each(_data, function(index, _data) {
                                    options[options.length] = new Option(_data.name, _data.id);
                                });
                            }
                        });
                        element.parent().show();
                    },
                    complete: function() {
                        $('.ajax-loader').hide();
                    }
                });
            }
        }
    });

The error occurs only when I submit the form after I change the option on the selectbox.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: