Cross browser AJAX function to dynamically load HTML

后端 未结 6 1764
清酒与你
清酒与你 2021-02-06 12:25

I\'m looking for an AJAX function to dynamically request an HTML page. I already found the following:

function ajaxinclude(url) 
{
   var page_request = false

         


        
6条回答
  •  眼角桃花
    2021-02-06 12:49

    You might use an IE version which your script does not support. Try it again with this code snippet added before your function. ajaxinclude() can then be shortened to

    function ajaxinclude(url)  {
        var req = new XMLHttpRequest;
        if(!req)
            return null;
    
        req.open('GET', url, false); // get page synchronously 
        req.send();
        return req.responseText;
    }
    

    As an aside: I generally dislike using frameworks - there's too much magic happening behind the scenes for me to feel comfortable...

提交回复
热议问题