href然后执行更多JS

href然后执行更多JS

本文介绍了如何在JavaScript中更改window.location.href然后执行更多JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码片段,点击链接执行,如下所示

I have code snippent which is executed on click of a link which is as below

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; 将页面重定向到其各自的页面,但这会停止执行旁边写的代码。现在我希望这个代码在写入时执行,即首先代码应该带我到相应的主页面,然后代码写入后必须执行并给我一个必需的输出。

in above code window.location.href=base_url+"main";redirects the page to its respective page but this stops the execution of the code written just next to it. Now I want this code to be executed as it is been written i.e. firstly the code should take me to the respective "main" page and then code writte after that must execute and give me a required output.

有人可以指导我实现这个目标吗?

Can someone guide me to achieve this?

推荐答案

window.location.href = base_url +main; < - 当您加载此页面时,请调用 ///下一步定义的代码

window.location.href = base_url + "main"; <- when you load this page, call your code defined at ///next

你必须添加一些参数:

window.location.href=base_url+"main?parameter=true";

另一种方法是将带有ajax的页面加载到html中的div中。

The other way would be to load the page with ajax into a div in the html.

从jQuery看一下 $。ajax()

Have a look at $.ajax() from jQuery.

这篇关于如何在JavaScript中更改window.location.href然后执行更多JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:16