带有重定向的页面的jQuery ajax请求,重定向我的整个页面。

时间:2014-02-26 21:13:22

标签: javascript jquery html get

我正在使用jQuery $.get方法检索html页面,然后将结果附加到div。

我正在检索的页面页面重定向到另一个页面(3秒后),但这会导致我的父页面重定向,而不是我想要的#mentions

$.get("index.php", {
    act: "Search", 
    CODE: 01, 
    keywords: nickName, 
    exactname: 1, 
    joinname: 1, 
    cat_forum: "forum", 
    forums: "all", 
    searchsubs: 1, 
    search_in: "posts", 
    result_type: "posts", 
    prune: 30, 
    prune_type: "newer", 
    sort_key: "last_post", 
    sort_order: "desc" 
}, function(data) { 
    $("#mentions").append(data); 
}, "html"); 

1 个答案:

答案 0 :(得分:0)

一种可能的解决方案是仅获取身体的内部:

$.get("index.php", {
    act: "Search",
    CODE: 01,
    keywords: nickName,
    exactname: 1,
    joinname: 1,
    cat_forum: "forum",
    forums: "all",
    searchsubs: 1,
    search_in: "posts",
    result_type: "posts",
    prune: 30,
    prune_type: "newer",
    sort_key: "last_post",
    sort_order: "desc"
}, function (data) {
    $("#mentions").append($(data).find("body").html());
}, "html");

注意:如果你在index.php中有特定的javascript和css需要运行,那就不行了,因为你需要一个iframe。