1

Hi I'm developing custom component in Joomla. After successful save, my controllers set's 303 redirect with custom message. But with the AJAX interface in middle, my page does not seems to get redirected to that page. It stays on same page.

AJAX Request Network Console

How do I handle 303 status code and force my page to redirect on page that is being set by controller?

Here is my js code:

$('#submit').click(function(e){
    $('.requestForm').ajaxSubmit({
        url: 'index.php?option=com_helpdesk&task=request.save',
        type: 'POST',
        beforeSubmit: function () {
            $.blockUI({css: {
                    border: 'none',
                    padding: '15px',
                    backgroundColor: '#000',
                    '-webkit-border-radius': '10px',
                    '-moz-border-radius': '10px',
                    opacity: .5,
                    color: '#fff'
                }});
        },
        success: function(result, status, xhr) {
            var response = $.parseJSON(result);
            if (!response['success'])
            {
                var html = '<div class="alert alert-warning alert-dismissible" role="alert">';
                html += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
                html += '<p><strong>Warning!</strong></p>';
                $.each(response['messages']['error'], function (index, value) {
                    html += '<p>' + value + '</p>';
                });
                html += '</div>';
                $('#system-message-container').html(html);
            }
            else
            {
                //Here my page get's 303 redirect which needs to be handle.
            }
        },
        statusCode: {
            // I tried this but this is not working
            303: function() {
                $.unblockUI();
                alert('hurray');
            }
        },
        complete: function () {
            $.unblockUI();
        }
    });
    e.preventDefault();
});
1

In Joomla, regular controllers save a redirect. On Ajax side, it is perfectly fine.

Instead of trying to avoid redirection, just write a specific save "saveAsync" in your controller, with no redirection.

In addition , some libraries like Backbone.JS or AngularJS submits forms in a different way (php input raw json) than common Joomla forms and it has to be handled accordingly in the controller.

  • This is what I did in my code. I completely overrided built in method with no redirection. I was just curious if we can handle 303 redirects through jquery. But I got the anwer as "No". Thank you for your help. – Sahil Purav May 7 '15 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.