Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Object doesn't support..." IE8 stops at declaring ordinary variable
    primarykey
    data
    text
    <p>I'm trying to make a form send its data through AJAX and cancel the event sans jQuery, just for learning native javascript, which can never be bad, i figured. Anyway, this code is returning the error "Object doesn't support this property or method" in IE8 at the line where I declare variables s and r in the send() function. I figured the problem must actually be elsewhere? Code works in both Firefox and Chrome, returning no errors. Ideas?</p> <pre><code>// Function to serialize form function serialize() { var a = document.getElementsByTagName('input'), b = ''; for (i = 0; i &lt; a.length; i++) { b += a[i].name + '=' + a[i].value + '&amp;'; } return b.substring(0, b.length - 1); } // Function to execute when user submits form function send(evt) { // Prevent the page from reloading if (evt.preventDefault) { evt.preventDefault(); } else { evt.returnValue = false; } // Declare DOM variables for quick access var s = document.getElementsByClassName('skicka')[0], r = document.getElementById('return'); // Hides the submit button and return text s.style.visibility = 'hidden'; r.style.visibility = 'hidden'; // Initialize and send data and request to login.php var xhr = new XMLHttpRequest(); xhr.open('POST', 'login.php', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send(serialize()); // Check for return value from login.php xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.responseText == true) { // If response if true, reload page window.location.reload(true); } else { // If response is false, reset form and show response s.style.visibility = 'visible'; r.style.visibility = 'visible'; r.innerHTML = xhr.responseText; } } }; return false; } // Declare event listeners if (window.addEventListener) { window.addEventListener('load', function() { document.forms[0].addEventListener('submit', send, false); }, false); } else { window.attachEvent('onload', function() { document.forms[0].attachEvent('onsubmit', function() { send(window.event); }); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload