Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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 jqueryajax请求页面重定向,重定向我的整个页面。_Javascript_Jquery_Html_Get - Fatal编程技术网

Javascript jqueryajax请求页面重定向,重定向我的整个页面。

Javascript jqueryajax请求页面重定向,重定向我的整个页面。,javascript,jquery,html,get,Javascript,Jquery,Html,Get,我正在使用jQuery$检索一个html页面。获取方法,然后将结果附加到一个div 我正在检索的页面重定向到另一个页面(3秒后),但这会导致我的父页面重定向,而不是我想要的#提及的 $.get("index.php", { act: "Search", CODE: 01, keywords: nickName, exactname: 1, joinname: 1, cat_forum: "forum", forums: "all

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

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

$.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"); 

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

$.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。

只是猜测(因为没有足够的信息来实际帮助您),您仍然在提交页面/表单。可能是缺少
返回false是否将整个html页面附加到div?将您的javascript代码添加到帖子中。@rlemon感谢您的快速回复。下面是代码$.get(“index.php”),{act:“Search”,代码:01,关键字:昵称,exactname:1,joinname:1,cat_论坛:“论坛”,论坛:“所有”,searchsubs:1,Search_in:“posts”,result_type:“posts”,prune:30,prune_type:“newer”,排序键:“last_post”,排序顺序:“desc”},函数(数据){(“#提及”)。追加(数据)},“html”);一切正常,数据成功地附加到div,但是当里面的数据(html文档)提到div时,重定向的页面会重定向到另一个页面(3秒后),重定向的页面不会停留在div中div@Slev7n好吧,我想我现在明白你的问题了。简单的答案是不要使用div,它们不是iframe。听起来您想在这里使用iframe。如果您专注于使用div,那么重定向就不能是重定向。您需要调用该ajax函数并再次替换div的内容。但正如我在开始时所说的,iframe很可能就是您想要的。@rlemon我用iframe替换了div,结果相同:(Console显示以下错误:未捕获错误:语法错误,无法识别的表达式这很奇怪,这里没有任何语法错误,只需更改$(“#提及”).append(数据);with$(“#提及”).append($(数据)。find(“body”).html());