javascript - 应该从不同网页加载内容的无响应 AJAX 代码

标签 javascript jquery ajax html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Tabs - Collapse content</title>
<link rel="stylesheet" href="jquery-ui.css">
<script src="jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="main.css">
<script>
$(function() {
    $( "#tabs" ).tabs({
     collapsible: true
   });
 });
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  $("#tabs-2").load("p2.html #content");
  </script>

</head>
<body>

<div id="tabs">
  <ul>
     <li><a href="#tabs-1">Alienware and Alpha</a></li>
     <li><a href="#tabs-2">More About</a></li>
     <li><a href="#tabs-3">Contact Us</a></li>
  </ul>
  <div id="tabs-1">
    <p><strong>Click this tab again to close the content pane.</strong>    </p>
    <p>Alienware is an American computer hardware subsidiary of Dell, Inc. Their products are designed for gaming purposes and are best known for their science-fiction-themed designs. Alienware was founded in 1996 by Nelson Gonzalez and Alex Aguila. Alienware Alpha is a line of PC-console hybrids introduced in 2014. It contains a custom-built Nvidia GeForce GTX 860M; a Core i3, i5, or i7 Intel Processor, depending on what model is purchased, up to 8 gigabytes of RAM; and between 500 gigabytes and 2 terabytes of hard drive space..</p>
  </div>
  <div id="tabs-2">
  </div>
.....(other ending tags, etc.)

我正在尝试从一个非常基本的网页加载内容,该网页除了带有 div 标签#content 的正文之外什么都没有。我希望它出现在我的选项卡 2 中。但它不会发生。我不确定我做错了什么。

p2.html: Ajax 选项卡 2

<body>
<div id="content">

    <p>Established in 1996 by Nelson Gonzalez and Alex Aguila, Alienware assembles desktops, notebooks, workstations, and PC gaming consoles. According to employees, the name "Alienware" was chosen because of the founders' fondness for the hit television series The X-Files, with names such as Area-51, Hangar 18, and Aurora.</p>
    </div>
    </body>
</html>

最佳答案

编辑、更新

yes on chrome browser!

尝试关闭chrome ,调整启动器,或从终端启动 /path/to/chrome --allow-file-access-from-files旗帜 。请参阅How do I make the Google Chrome flag "--allow-file-access-from-files" permanent? , --allow-file-access-from-files 。另请参阅chrome://flags

<小时/>

$("#tabs-2")未定义时 .load()称为 <script></script>包含$("#tabs-2").load("p2.html #content"); <head></head>内元素?

尝试移动$("#tabs-2").load("p2.html #content"); $(function() {})

  $(function() {
    $( "#tabs" ).tabs({
      collapsible: true
    });
    $( "#datepicker" ).datepicker();
    $("#tabs-2").load("p2.html #content");
  });

关于javascript - 应该从不同网页加载内容的无响应 AJAX 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33314302/

相关文章:

jquery - 使用 jQuery 和 Ajax 为所有用户更改元素的样式

javascript - Django Ajax POST 空错误 500

javascript - jQuery的append和wrap的区别

javascript - 如何将 Prop 传递给第三方组件?

javascript - 使用 javascript 或 php 动态且唯一地注入(inject) URL 的最后部分

jQuery:将内容添加到div末尾

javascript - 如何比较两个 jQuery 对象的身份?

javascript - 如何为我的函数访问数组中的属性?

javascript - zend 表单验证需要 JavaScript 吗?

javascript - 有时卡住浏览器后的 Ajax 请求