4

I have been trying to figure this out all afternoon, but have given up and now turning to you clever people to help :)

I have the following Jquery/Javascript function, which is working fine in Chrome - BUT in IE nothing happens?

    $(".btnsubmitpost").click(function () {
    var topicid = $(this).attr('rel');
    var sbody = tinyMCE.get('txtPost').getContent();
    $('.topicpostlistnewpost').remove();
    $('.postsuccess').show();
    $.post("/myurl/" + topicid + ".aspx",
           { "postcontent": sbody },
            function (data) {
                var returnUrl = $("value", data).text();
                window.location.href = returnUrl;
                return false;
            });
    return false;
});

I have tried window.location, window.location.href both with full urls and absolute Urls but IE just doesn't like it? Any ideas?

The function just gets a Url back from a post, and is supposed to redirect the user to the Url. But like I say, works in Chrome fine just not in IE (Tried IE8 and IE9)

YodasMyDad
  • 9,248
  • 24
  • 76
  • 121
  • Can you debug and find in IE what does `returnUrl` contain? – ShankarSangoli Jan 10 '12 at 19:12
  • 1
    don't `return false` from your inner function. – Jamie Treworgy Jan 10 '12 at 19:13
  • Check this link it may help: http://stackoverflow.com/questions/4818868/window-location-not-working-correctly-in-ie7-8 – Suave Nti Jan 10 '12 at 19:42
  • returnUrl is either returning /mypage.aspx?p=12 or http://mydomain.com/mypage.aspx?p=12#comment12? As I say, its working in Chrome and its not the 'returnUrl'. I shall try and remove the return false from the inner function and see if that sorts it – YodasMyDad Jan 10 '12 at 19:56
  • nope removing the return false makes no difference, I actually completely removed it and tried event.preventDefault() but still it just doesn't redirect - Checked url in debugger and its fine? – YodasMyDad Jan 10 '12 at 20:10

1 Answers1

3

Just for anyone having the same issue, the problem was because the window.location was inside the Ajax post method.

Just replace the window.location with a function() that then calls the window.location or do it after the Ajax call completely.

YodasMyDad
  • 9,248
  • 24
  • 76
  • 121