-2

I specify IE in the title because my code works as intended on Chrome. Essentially I have one view called "Maintenance" that is used for creating, editing, and deleting. The form itself is contained in a partial view (coincidentally called "_MaintenanceForm") which has it's own GET/POST methods to submit the form. Here is the form. Sorry I had to use Pastebin instead of inline code blocks--they were making me go over the character limit.

Note that the form has id #maintenanceForm. Instead of using an AJAX call to submit this form I just use the jQuery function $("#maintenanceForm").submit(); so I don't need to pass all of the fields as data. Here is my JavaScript for the Maintenance page.

I know that the .submitForm click function is defined twice which is redundant code but I originally had it as a separate function which was causing problems so I defined it anonymously inline instead. I can focus on cleaning up my code once I get it working in IE.

My Maintenance view is really simple, it's just a <div class="maintenance-form"></div> that the MaintenanceForm partial is rendered in using the first AJAX call. Here are my controller methods. Essentially the problem I'm running into is that in Chrome, after the MaintenanceForm POST method, the Maintenance GET method is called which re-renders the view. When the view is re-rendered, the MaintenanceForm GET and SearchTable2 methods are called again through the AJAX call. In IE, the Maintenance GET method is called but the AJAX calls are not resubmitted so the form does not refresh. As a result I need to manually refresh the pages to see the changes made.

As I said, this works exactly as I want it to in Chrome but not IE, so I know it must be some sort of IE compatibility issue, but I can't figure it out for the life of me. Thanks in advance for any help and let me know if providing more code would help!

B. Fitzgerald
  • 135
  • 1
  • 16
  • [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask/) – Andreas Jul 19 '17 at 16:47
  • @MichaelCoxon I didn't know to search for "caching". I did a lot of searches and couldn't find anything so I asked my own question. Adding `$.ajaxSetup({ cache: false });` did work, though, so if you'd like to make that an answer I'll gladly accept. Thanks for your help! – B. Fitzgerald Jul 19 '17 at 17:39

1 Answers1

0

@Michael Coxon was correct, IE caches ajax calls. Try

$.ajaxSetup({ cache: false });

This should allow your window to refresh each time your Maintenance GET method is called. If you wanted this to not cache only in IE, try

var ieVersion = (function() { if (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) { return parseFloat( RegExp.$1 ); } else { return false; } })();// IE <= 10
var isIE2 = '-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style;// IE 11
if(ieVersion < 11 || isIE2) {
    $.ajaxSetup({ cache: false });
}

which is sort of hackish, but restricts that operation to any version of IE

reference: http://api.jquery.com/jquery.ajax/

bowl0stu
  • 352
  • 1
  • 12