IE does not resend AJAX calls after form submit

    |
  • Added:
  • |
  • In: Wordpress

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!

This Question Has 1 Answeres | Orginal Question | B. Fitzgerald

@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/


Search
I am...

Sajjad Hossain

I have five years of experience in web development sector. I love to do amazing projects and share my knowledge with all.

NEED HOSTING?
Are you searching for Good Quality hosting?
You can Try It!
Connect Social With PHPAns
Top