eldan88 Posted January 31, 2014 Share Posted January 31, 2014 Hey guys. I am new to using javascript with ajax. I want to get my hands dirty using javascript and ajax before moving on to jquery... I am trying to request a simple txt document, but my console.log is keep giving me the following.. Uncaught InvalidStateError: Failed to execute 'send' on 'XMLHttpRequest': the object's state must be OPENED. request.onreadystatechange Any idea on how to correct this? Below is my code. var request = new XMLHttpRequest(); request.open('GET', 'data.txt', true); request.onreadystatechange = function() { if((request.readyState === 4) && (request.status === 200)) { request.send(); console.log(request); document.write(request.responseText); } } request.send(); Quote Link to comment https://forums.phpfreaks.com/topic/285816-need-help-making-a-simple-requestnewbie-question/ Share on other sites More sharing options...
Solution eldan88 Posted January 31, 2014 Author Solution Share Posted January 31, 2014 Never mind! I solved the issue! Quote Link to comment https://forums.phpfreaks.com/topic/285816-need-help-making-a-simple-requestnewbie-question/#findComment-1467252 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.