Search code examples
jqueryfirefoxhttp-redirectpost-redirect-get

jquery.redirect issue in Firefox, works in Chrome


I have the following jQuery redirect code (using jquery.redirect.js):

jQuery.redirect plugin doc

        <script type='text/javascript'>
        $ = jQuery.noConflict();
            $.redirect('https://direct.tranzila.com/hatunot/', {"sum":289,"pdesc":"1 x \u05d1\u05d2\u05d3 \u05d2\u05d5\u05e3 \u05dc\u05d1 \u05e9\u05de\u05e0\u05ea \u05e4\u05e8\u05d7\u05d5\u05e0\u05d9","contact":"\u05d8\u05dc \u05d1\u05d9\u05d3\u05e7\u05d4","company":"Personal","email":"taltest@gmail.com","phone":"555555","fax":"","address":"\u05d3\u05d2\u05db\u05d3\u05d2 \u05d3\u05d2\u05db\u05d3\u05d2","city":"\u05d3\u05d2\u05db\u05d3\u05d2\u05db","remarks":"","currency":"1","myid":"","TranzilaToken":"orGzf5G2ZQ3LTNlbiepXc1l4O6ll3Rln9yQG_PLUS_17mV06u8iwZkBGz_SLASH_v97O1_SLASH_jzBXgl0LW_SLASH_jstL_SLASH_ywDjepwyuCS0YBYTkEPUtrqwJsNQrNZUQ_EQUALS_","orderid":1801,"cred_type":"1"}, 'POST')           </script>

Works perfectly in Chrome, and browser redirects to the above address with all the parameters, but it will not redirect with Firefox.

I created a simple test page - http://mydayshop.co.il/test.php - will work in IE/Chrome, but not in Firefox.

No errors logged in console/firebug.

What could be the case for Firefox not redirecting ?


Solution

  • In jquery.redirect.js, jQuery( html, attributes ) way is not working in Firefox.

    I modified the code & now your problem can be fixed using modified version of jquery.redirect.js:

    /* jQuery POST/GET redirect method
       v.0.1
        modified by Miguel Galante,https://github.com/mgalante
       v.0.1
       made by Nemanja Avramovic, www.avramovic.info 
       */
    
    ;(function( $ ){
    
        $.redirect = function( target, values, method ) {  
    
            method = (method && method.toUpperCase() == 'GET') ? 'GET' : 'POST';
    
            if (!values)
            {
                var obj = $.parse_url(target);
                target = obj.url;
                values = obj.params;
            }
    
            var form = $('<form>');
                form.attr('method', method);
                form.attr('action', target);
    
            for(var i in values)
            {
                var input = $('<input>');
                    input.attr('type', 'hidden');
                    input.attr('name', i);
                    input.attr('value', values[i]);
                    input.appendTo(form);
    
            }
    
    
    
            $('body').append(form);
        //console.log(form);
        form.submit();
        };
    
        $.parse_url = function(url)
        {
            if (url.indexOf('?') == -1)
                return { url: url, params: {} }
    
            var parts = url.split('?');
            var url = parts[0];
            var query_string = parts[1];
    
            var return_obj = {};
            var elems = query_string.split('&');
    
            var obj = {};
    
            for(var i in elems)
            {
                var elem = elems[i];
                var pair = elem.split('=');
                obj[pair[0]] = pair[1];
            }
    
            return_obj.url = url;
            return_obj.params = obj;
    
            return return_obj;      
        }   
    })( jQuery );