jQuery Ajax and redirect response from server

The server can not do a redirect from an ajax request. In the end ajax involves the client (browser). If you want to redirect you can do it, but it is going to have to be done on client side, in the callback. You can do that by returning an object from the server which contains the url you want to redirect to--- you can then you javascript to change the document's location property. I would think that this would make sense if you were not redirecting in all cases, or if your server side call was a long running process. If neither is the case then an ajax call probably doesn't make sense in the first place.


I may be misreading your question, but where is your success callback function in that ajax call? That is where you would typically render the results into the view, also, you could use the error callback to get some data on what, if anything is going wrong:

function chkSubmit(event, actionType) {


        var msgid = showlst('Please wait ...');
        var actionType = type // per j. tuskan - looks like no such var in scope
        var data = ''
        if (actionType == 'IAmDone') {
            var letters = 'e,b,c'

            data = 'actionType=' + actionType + '&letters=' + letters;

        } else data = 'actionType=' + actionType;
        $j.ajax({
            type: 'POST',       
            url: context + '/app/handleChk',
            data:  data,
            success:function(the_data){
              alert("Now I can do stuff with the ajax response which is: "+the_data);
            }
        });

        return false;
}

Example of what has been said by @ek_ny.

jQuery.ajaxSetup({
    complete: function (request, textStatus) {
        // header inserted manually on the server.
        // you should block the automatic redirect headers 
        // inserted by the server.
        var location = request.getResponseHeader("Location");
        if(location) window.location = location; 
    }
});