Welcome Guest, Not a member yet? Register   Sign In
Put or handle base_url in file .js.. [solved]
#1

[eluser]tnathos[/eluser]
Hi.. in my app i use file .js for handled events ajax.. whit this events use in severals i ut this funcions in external .js for include in each view..

So all works fine.. but now i have 2 enviroments for development + production.. and if i need test the app i need chagen always the route in the calls ajax.. i have this for example..

Code:
function borrar_fav_oferta(id_proceso)
{
    $.ajax({
           type: "POST",
           url: "http://localhost:8888/misyte/favoritos/del_fav_oferta/",
           cache: false,
           data: "id_proceso="+id_proceso,
           success: function(msg){
        document.getElementById("cont_compartir")[removed] = msg;    
        $("#cont_mensaje").modal({
            opacity:80,
            overlayCss: {backgroundColor:"#222222"}
            });    
        location.href="http://localhost:8888/misyte/favoritos/ofertas/"
        }        
    });
}

so i need chagne always "http://localhost:8888/misyte/" for the domain.. in all files!!

i try del http://localhost:8888/misyte/ and works but only when i have a location.href.. but when i call the ajax.. in the param url:.. dont works.. any can help me? hiw i can del "http://localhost:8888/misyte/" forn the js for all calls?

thanks
#2

[eluser]InsiteFX[/eluser]
Try this in your code.

Code:
var base_url = base_url();

Enjoy
InsiteFX
#3

[eluser]Kamarg[/eluser]
You can also use the base tag in your html head tag so that you don't need the base url in your .js files.
#4

[eluser]tnathos[/eluser]
ok solved.. if any have te problem similar..

if use a path relative for call the ajax have a problem because whit use the same .sj in others views and model the path relative fail..

so the solution its create in the head a global variable for js and this variable set the php variable.. and in the files .js using this var.




Theme © iAndrew 2016 - Forum software by © MyBB