开发者

Simple ajax not working, probably syntax error

开发者 https://www.devze.com 2022-12-13 18:26 出处:网络
window.onloa开发者_运维百科d = function(){ testAjax(); } var testAjax = function(){ var request = window.ActiveXObject ? new ActiveXObject(\"Microsoft.XMLHTTP\") : new XMLHttpRequest();
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消