Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Joe Shiels
19,933 PointsLoading message not showing in Google Chrome (AJAX)
HTML:
Your First Name: <input type="text" id="first_name" name="first_name" />
You Last Name: <input type="text" id="last_name" name="last_name" />
<input type="submit" name="myBtn" value="Submit Data" onclick="ajax_post();" /><br />
<div id="status"></div>
JavaScript:
function ajax_post() {
var hr = new XMLHttpRequest();
var url = "my_parse_file.php";
var fn = document.getElementById("first_name").value;
var ln = document.getElementById("last_name").value;
var vars = "firstname="+fn+"&lastname="+ln;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}else {
document.getElementById("status").innerHTML = "Loading ...";
}
}
hr.send(vars);
document.getElementById("status").innerHTML = "Loading ...";
}
I have tried this code in Google Chrome, Safari, Opera, Firefox and IE. It can send ad retrieve data fine in all browsers. But in Google Chrome and Firefox the loading message doesn't display it just delays. Why is this?
1 Answer
Richard Duncan
5,568 PointsUnless you are handling a large amount of data or a large number of requests I wouldn't normally expect to see the loading message displayed.