Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ajax动态加载页面_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 使用ajax动态加载页面

Javascript 使用ajax动态加载页面,javascript,jquery,ajax,Javascript,Jquery,Ajax,这是我的javascript代码,用于动态加载网页的主要内容,但内容片段没有加载,加载图标永远在运行,控制台给出“Uncaught TypeError:$ajaxUtils.sendGetRequest不是HTMLDocument的函数。” $(函数(){//与document.addEventListener相同(“DOMContentLoaded”。。。 //与document.querySelector(“#navbatogle”).addEventListener(“blur”)相同,。

这是我的javascript代码,用于动态加载网页的主要内容,但内容片段没有加载,加载图标永远在运行,控制台给出“Uncaught TypeError:$ajaxUtils.sendGetRequest不是HTMLDocument的函数。”

$(函数(){//与document.addEventListener相同(“DOMContentLoaded”。。。
//与document.querySelector(“#navbatogle”).addEventListener(“blur”)相同,。。。
$(“#navbarToggle”).blur(函数(事件){
var screenWidth=window.innerWidth;
如果(屏幕宽度<768){
$(“#可折叠导航”).collapse('hide');
}
});
});
(职能(全球){
var dc={};
var homeHtml=“snip/home snippet.html”;
var insertHtml=函数(选择器,html){
var targetElem=document.querySelector(选择器);
targetElem.innerHTML=html;
};
var showLoading=函数(选择器){
var html=“”;
html+=“”;
insertHtml(选择器,html);
};
document.addEventListener(“DOMContentLoaded”),函数(事件){
展示加载(“主要内容”);
$ajaxUtils.sendGetRequest(
homeHtml,
函数(responseText){
文档查询选择器(“主要内容”)
.innerHTML=响应文本;
},
假);
});
全球.$dc=dc;
})(窗口);

那么,
$ajaxUtils
是在哪里定义的呢?请尝试添加示例运行代码,以确定您使用了哪些库。
$(function () { // Same as document.addEventListener("DOMContentLoaded"...
    
      // Same as document.querySelector("#navbarToggle").addEventListener("blur",...
      $("#navbarToggle").blur(function (event) {
        var screenWidth = window.innerWidth;
        if (screenWidth < 768) {
          $("#collapsable-nav").collapse('hide');
        }
      });
    });
    
    
    (function (global) {
    
    var dc = {};
    
    var homeHtml = "snip/home-snippet.html";
    
    var insertHtml = function(selector, html) {
        var targetElem = document.querySelector(selector);
        targetElem.innerHTML = html;
        };
    
    var showLoading = function (selector) {
        var html = "<div class='text-center'>";
        html += "<img src='load.gif'></div>";
        insertHtml(selector, html);
    };
    
    document.addEventListener("DOMContentLoaded", function (event) {
    
     showLoading("#main-content");
     $ajaxUtils.sendGetRequest(
        homeHtml,
        function (responseText) {
            document.querySelector("#main-content")
              .innerHTML = responseText;
        },
        false); 
    });
    
    global.$dc = dc;
    
    })(window);