为什么这不工作? jQuery的阿贾克斯替换特定的DIV内容这不、内容、工作、jQuery

2023-09-10 17:30:34 作者:命运好幽默

下面我有code我的网站上,但是当我的点击的在这个特殊的 DIV 它只是打开一个新的窗口,这是为什么?

Below I have the code on my site, yet when I click on a link in this particular div it just opens a new window, why is this??

$(function(){   
//bind a click event to the nav links
$("#links a").bind("click", function(e){ 

    //keep the links from going to another page by preventing their default behavior
    e.preventDefault();

    //this = link; grab the url
    var pageLocation = this.href;

    //fire off an ajax request
    $.ajax({ 
        url: pageLocation, 

        //on success, set the html to the responsetext
        success: function(data){ 
            $("#biocontent").html(data.responseText); 
        } 
    });
});
});

编辑:

我还是havnt想通了这一点,但这里是我在哪里,我的脚本如下

I still havnt figured this out but here is where I am, my script is as follows

  <script type="text/javascript">(function(){   
//bind a click event to the nav links
$("#links a").bind("click", function(e){ 

    //keep the links from going to another page by preventing their default behavior
    e.preventDefault();

    //this = link; grab the url
    var pageLocation = $(this).attr("href")

    //fire off an ajax request
   $.ajax({ 
    url: pageLocation, 

    //on success, set the html to the responsetext
    success: function(data){ 
        $("#biocontent").html(data); 
    },
    dataType : "html"
     });
});

});

和这里是我如何使用它在我的HTML &LT; D​​IV ID =链接&GT;             &LT; A HREF =testvid.html&GT;&LT; IMG SRC =IMG /大拇指/ img3.jpg/&GT;&LT; / A&GT;

and here is how I am using it in my html<div id="links"> <a href="testvid.html"><img src="img/thumbs/img3.jpg" /></a>

但仍然没有去,请让我知道你在想什么。

but still no go, please let me know what you think.

修改

所以我把这个code中的最小的零件和移动到一个新的文档,而现在它不工作在所有,但我觉得我有一个问题,Jquery的,所以现在的工作,我得到了这个错误

So I took the minimal parts of this code and moved it into a new doc, and now it doesnt work at all, but i feel like I was having an issue with the Jquery, so now it is work and I am getting this error in the

17XMLHtt prequest无法加载文件:///Users/semaj4712/Desktop/WME%20Website/testvid.html。原产地空不受访问控制 - 允许 - 产地允许的。

17XMLHttpRequest cannot load file:///Users/semaj4712/Desktop/WME%20Website/testvid.html. Origin null is not allowed by Access-Control-Allow-Origin.

这我不知道这意味着什么,所以一旦我得到它的工作在这里,然后我不得不解决的问题Jquery的实际现场。

Which I have no idea what that means, so once I get it working here then I have to tackle the issue with the Jquery on the actual site.

推荐答案

您应该调用Ajax和你想获得指定的类型。

You should call ajax with specified type that you want to get.

 $.ajax({ 
        url: pageLocation, 

        //on success, set the html to the responsetext
        success: function(data){ 
            $("#biocontent").html(data); 
        },
        dataType : "html"
    });