Simple ajax not working, probably syntax error
window.onloa开发者_运维百科d = function(){
testAjax();
}
var testAjax = function(){
var request = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
request.onreadystatechange = function(){
if (request.readyState == 4){
// Server is done
try{
var p = document.getElementById['a'];
p.innerHTML = request.responseText;
//document.write(request.responseText);
}
catch(e){
document.write('More Epic Fail');
}
}
}
request.open('GET','updatethumbs.php',true);
request.send(null);
}
After a quick glance:
var p = document.getElementById['a'];
should be:
var p = document.getElementById('a');
getElementById should have ()'s, not []'s
Yup, use "rounded brackets"/parenthesis ()
There are a few names for the MSXML component and depending on what the user (in this case, you) has installed, it may not work.
EDIT: (as per question edit)
Browsers are not required to redraw the page once it's been rendered according to the CSS spec. You need to use javascript to style the items that are dynamically added in.Try, for example:
document.getElementById('a').style.border = "1px solid black";
for a simple black border.
精彩评论