3

I have a following javascript function mixed with MVC controller actions calls:

var loadPartialChapterAfterAnswer = function () {
        $.ajax({                
            url: '@Url.Action("IsAuthenticated", "Story")',
            type: "POST",
            success: function(data) {
                var isAuthenticated = data;
                if (isAuthenticated) {
                    if ('@Model.IsPersonality' == 'True') {
                        loadPartialChapter();
                    } else {
                        $("#chapterContainer").load('@Url.Action("GetNextQuestion", "Story")' + '?storyId=' + '@Model.Id', function () {
                            selectedCounter = 0;
                            showOnlyOneQuestion();
                        });
                    }
                } else {
                    window.location.href = '@Url.Action("RedirectToHomeRoute", "Home")';
                }
            },
            error: function() {
                alert("Error");
            }
        });
    };

Every time I select one checkbox on my page(view) this function is called. Code works great in all browsers except in IE. In IE the ajax url @Url.Action("IsAuthenticated", "Story") is called OK every time, but the other controller action '@Url.Action("GetNextQuestion", "Story")' + '?storyId=' + '@Model.Id' is called only when the IE's browser debugger is turned on. When IE's debugger window is off this second MVC action is never called.

Any help is highly appreciated!

SOLUTION

I added at the beginning of my page this code:

<script>
    $.ajaxSetup({
        cache: false
    });
</script>

and now it works! Thanks all for your effort.

kiriz
  • 655
  • 1
  • 7
  • 24
  • By the way: '@Url.Action("GetNextQuestion", "Story")' + '?storyId=' + '@Model.Id' is the same as '@Url.Action("GetNextQuestion", "Story")' + '?storyId=@Model.Id' – Alex Art. Sep 17 '14 at 15:05
  • The problem with IE it store almost everything in cache. In your ajax you must specify "cache: false," attribute so the request will have a timestamp so IE now will execute the action from the controller everytime – Jorge F Sep 18 '14 at 02:17
  • @AlexArt - yeah, I know, but its not a big deal... – kiriz Sep 18 '14 at 07:29
  • @JorgeF - cache: false unfortunately didn't help... – kiriz Sep 18 '14 at 07:31
  • On http://stackoverflow.com/questions/15949819/ie9-script-only-works-in-debugger-but-not-when-not-debugging ppl say that IE tends to crash on console.log() (and other console methods) unless the debugger is open. I tried not to include scripts that have console, console.log() in them, but it didn't help. – kiriz Sep 18 '14 at 07:58
  • Could you try maybe using $.get or regular $.ajax instead of $.load and to check if you have the same error? – Alex Art. Sep 18 '14 at 08:10

2 Answers2

2

I read something about IE having issues with JQuery load function Try to replace it with regular $.ajax with cache: false option hopefully it will resolve the issue.

Check this topic

Community
  • 1
  • 1
Alex Art.
  • 8,711
  • 3
  • 29
  • 47
0

Add controller to this: @Url.Action("GetNextQuestion")' Without controller specified it place controller which return view last.

aleha_84
  • 8,309
  • 2
  • 38
  • 46
  • I added the controller name, it didn't help. – kiriz Sep 17 '14 at 14:07
  • @kiriz have you tried to test this in other browsers? – aleha_84 Sep 17 '14 at 14:13
  • As I said in my question, this functionality works 100% in all other browsers. OK, I tested it only in Chrome and Firefox. ;) – kiriz Sep 17 '14 at 14:19
  • @kiriz have you notice any difference in url generated by razor between these browsers? Can you load page in IE without enabled it's browser debugger and after load has been completed enable it and check generated url. Or you can alert it on document ready event, to avoid using debugger. – aleha_84 Sep 17 '14 at 14:39
  • I solved my issue. U can check it out at the bottom of my question. – kiriz Sep 18 '14 at 09:51