Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change window.location.href in JavaScript and then execute more 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'); 

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?

like image 325
OM The Eternity Avatar asked Nov 21 '11 09:11

OM The Eternity


1 Answers

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

you will have to add some parameters:

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

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

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

like image 195
Rumplin Avatar answered Nov 09 '22 08:11

Rumplin