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.

6
  • By the way: '@Url.Action("GetNextQuestion", "Story")' + '?storyId=' + '@Model.Id' is the same as '@Url.Action("GetNextQuestion", "Story")' + '[email protected]' Commented Sep 17, 2014 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 Commented Sep 18, 2014 at 2:17
  • @AlexArt - yeah, I know, but its not a big deal... Commented Sep 18, 2014 at 7:29
  • @JorgeF - cache: false unfortunately didn't help... Commented Sep 18, 2014 at 7:31
  • On stackoverflow.com/questions/15949819/… 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. Commented Sep 18, 2014 at 7:58

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

5 Comments

I added the controller name, it didn't help.
@kiriz have you tried to test this in other browsers?
As I said in my question, this functionality works 100% in all other browsers. OK, I tested it only in Chrome and Firefox. ;)
@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.
I solved my issue. U can check it out at the bottom of my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.