HTA无需AJAX jQuery将内容加载到div中

时间:2019-04-27 00:01:58

标签: javascript html ajax hta

我有一个HTA,我正在尝试将html内容从外部文件加载到其中。选择的方法是AJAX,但不幸的是,您无法在HTA中做到这一点。但是,我已经找到了执行此操作的纯JavaScript方法,但是在request.open行中我一直拒绝访问。有任何解决方法的想法吗?

  <!DOCTYPE html>
  <html lang="en-US">
  <head>
  <title>test file</title>
  <hta:application id="test app">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta charset="UTF-8">
  <script type="text/javascript" src="resources/js/jquery-3.3.1.js"> 
  </script> 
  <script type="text/javascript"  charset="utf8" src="resources/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript"  charset="utf8" src="resources/js/dataTables.scroller.min.js"></script>
  <link rel="stylesheet" type="text/css" href="resources/css/navigation.css">
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
  <link rel="stylesheet" type="text/css" href="resources/css/scroller.dataTables.min.css">  
  <link rel="stylesheet" type="text/css" href="https://www.w3schools.com/w3css/4/w3.css">    
  <link rel="stylesheet" type="text/css" href="resources/css/style.css">      
  </head>
 <body>
 <div class="header"></div>
<input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
 <div class="spinner diagonal part-1"></div>
 <div class="spinner horizontal"></div>
 <div class="spinner diagonal part-2"></div>
</label>
<div id="sidebarMenu">
 <ul class="sidebarMenuInner">
   <li><a href="#" id ="ajaxjestid" target="_blank">nav1</a></li>
</ul>
</div>    

<div id="ajaxtest"></div>
<!-- Footer -->
<footer >
<script language="javascript">
function myFunction() {
var request = new XMLHttpRequest();
request.open('GET', 'resources/html/ajaxtest.html', true);
request.onload = function() {
    if (request.status >= 200 && request.status < 400) {
        var resp = request.responseText;
        document.querySelector('#div').innerHTML = resp;
}
};
request.send();
}

$('#ajaxjestid').click(function(){ myFunction(); return false; });

</script>
</footer>
</body>
</html>

0 个答案:

没有答案