Adding things into the DOM in IE8 was going horribly wrong. Updating a segment of code after an AJAX post request was then breaking any subsequent requests.
After many hours trying to figure out what the problem could possibly be, it became apparent that the form action attribute was to blame.
It turns out that when IE8 inserts HTML into the DOM using the html() function, it likes to mangle perfectly good HTML. The form element was getting its attribute rearranged so that the action attribute came last in the ordering. Not only this but the quotation marks were also being stripped. The URL in the action attribute had a trailing slash, as required when doing POST requests* via forms. All of this together was causing IE8 to see:
<form ...snip... action=/some/path/ >
Rather than assume the trailing slash belonging to the URL it was closing the form prematurely.
(Thanks to http://richardmiller.co.uk/2011/03/11/jquery-ie8-bug-when-adding-a-form/ for a good explanation of this).
Don’t use the html() function. Turning
$("#element_id").innerHTML = $some_html.innerHTML;
works just fine. In fact, doing anything to prevent the action attribute from being put at the end of the form element will do the trick.
* Leaving off the trailing slash causes most webservers to do a re-direct. POST requests are not supposed to follow redirects without confirmation from the client. Sure, sometimes browsers will do this for you and there will be no problem but it’s better to just do it properly in the first place and avoid the second hit on the webserver.
Good practice in software development has always preached loose coupling and high cohesion.
While most developers understand this and try ...
There was a question raised by a collegue of mine recently, that asked "How long should it take to get ...
Salt is an open source infrastructure management tool. While one use is to manage thousands of servers, it’s also very ...