Call a url from javascript

后端 未结 4 1161
陌清茗
陌清茗 2020-12-15 07:50

Is there a way to call a url and get a response using javascript? I need the equivalent of ASP.NET:

WebRequest req = HttpWebRequest.Create(\"http://someu         


        
4条回答
  •  借酒劲吻你
    2020-12-15 08:35

    var req ;
    
    // Browser compatibility check          
    if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
    
     try {
       req = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
    
       try {
         req = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (e) {}
     }
    
    }
    
    
    var req = new XMLHttpRequest();
    req.open("GET", "test.html",true);
    req.onreadystatechange = function () {
        //document.getElementById('divTxt').innerHTML = "Contents : " + req.responseText;
    }
    
    req.send(null);
    

提交回复
热议问题