【发布时间】:2011-11-21 09:23:14
【问题描述】:
我有代码片段,点击下面的链接就会执行
cj_redirecturl="/HomeWork/main/load_course";
utility.xhttprw.data(cj_redirecturl,{data:courseid},function(response){
if(response){
window.location.href=base_url+"main";
///next
utility.xhttprw.data(redirecturl,{data:""},function(response){
if(response){
id=ent;
document.getElementById('content').innerHTML=response;
// Assignemnt module
//Call function from javascript/assignment.js file to display particular assignment (ent:means assignment_id) //
if(con==5)
{
get_assignment_id(ent);
}
if(con==9)
{
get_content_details(ent);
}
} //end of response
},false,false,false,'POST','html',true);
}
},false,false,false,'POST','html');
在上面的代码中window.location.href=base_url+"main";将页面重定向到其各自的页面,但这会停止执行写在它旁边的代码。现在我希望这段代码在编写时执行,即首先代码应该将我带到相应的“主”页面,然后必须执行之后写入的代码并给我一个所需的输出。
有人可以指导我实现这一目标吗?
【问题讨论】:
-
这不会像那样工作,当你重定向你得到另一个页面加载时,这意味着你失去了你在 javascript 内存中保存的所有内容。向重定向添加一个参数,通过该参数您可以知道何时重定向并在页面加载时对其进行处理
-
既然你标记了jquery,我想知道这里的jquery代码是什么
-
请更改此代码 document.getElementById('content').innerHTML=response;到这个 $('#content').html(response);
标签: javascript jquery window.location