Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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 jquery加载或发布_Javascript_Jquery_Html - Fatal编程技术网

Javascript jquery加载或发布

Javascript jquery加载或发布,javascript,jquery,html,Javascript,Jquery,Html,我试图使用jquery通过.load()函数在div标记中加载外部html文件,但它不起作用。它没有加载。代码如下: 我做错了什么?我得到错误{“error”:“请使用POST请求”} 但无论我使用.post还是.load,结果都是一样的。内容未显示。怎么了?请帮忙 <body> <div id="header"> <div id="logo"><a href="index.html"><img src="images/logolanha

我试图使用jquery通过.load()函数在div标记中加载外部html文件,但它不起作用。它没有加载。代码如下:

我做错了什么?我得到错误{“error”:“请使用POST请求”} 但无论我使用.post还是.load,结果都是一样的。内容未显示。怎么了?请帮忙

<body> 
<div id="header">
<div id="logo"><a href="index.html"><img src="images/logolanhai.jpg"    
alt="" /></a></div>
 <ul>
<li><a href="" onclick="about();"><span>关于我们</span></a></li>
<li><a href="" onclick="services();"><span>服务项目</span></a></li>
<li><a href="" onclick="references();"><span>成功案例</span></a></li>
<li><a href="" onclick="contact();"><span>联系我们</span></a></li>
</ul>    
 </div>


<div id="bodyinsert"></div>
</body>

function about()
{
$.post( "about.html", function( data ) { $( "bodyinsert" ).html( data );
});

//   $("#bodyinsert").load("about.html");
}

function services()
{


   $("#bodyinsert").load("services.html");

}

function references()
{


   $("#bodyinsert").load("references.html");

}

function contact()
{


   $("#bodyinsert").load("contact.html");

}

函数about() { $.post(“about.html”,函数(数据){$(“bodyinsert”).html(数据); }); //$(“#bodyinsert”).load(“about.html”); } 职能服务() { $(“#bodyinsert”).load(“services.html”); } 函数引用() { $(“#bodyinsert”).load(“references.html”); } 功能联系人() { $(“#bodyinsert”).load(“contact.html”); }
  • 据我所知,JSFiddle和StackSnippets都不允许AJAX(除了特定的JSFiddle页面)在控制台中查找错误
  • 获取HTML页面的帖子可能不是您想要的
  • $(“#bodyinsert”).load(“about.html”)很可能是您想要的-它确实意味着页面必须来自同一服务器,与您的脚本来源相同-您不能在Chrome to文件系统中使用AJAX
    还可以帮自己一个忙,使用href或数据属性作为URL,并在单击时使用默认值

    $(函数(){
    $(“.nav”)。在(“单击”上,函数(e){
    e、 preventDefault();//停止链接
    $(“#bodyinsert”).load(this.href);
    });
    });