Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:31:13+00:00 2026-06-13T22:31:13+00:00

Im having troubles sending a variable from php to javascript. I pull javascript (Ajax)

  • 0

Im having troubles sending a variable from php to javascript.

I pull javascript (Ajax) trough this link.

<script src="<?php echo base_url().'assets/js/main.js' ?>"></script>

In my main.js :

var base_url = '<?php echo base_url(); ?>';
var language = '<?php echo $language; ?>';

Im trying to load content dynamically without refresh webpage, by using ajax .load this way:

var addressValue = $(this).children('a').attr("href");

$('#conteudo').fadeOut("slow").load(addressValue+'/index.php?idioma='+language+' #conteudo').hide().fadeIn("slow")

I can load perfectly with the addressValue onyl.
But when i try the way above, my language won’t echo.
If instead of using language i put the language i want without variable e.g. portuguese it works like a charm.
im working with multilanguage so i need to pull the content in the language the user did choose.

This is how user can set language

<ul class="nav pull-right language" id="barra_de_idiomas">
    <li><?php echo anchor(($this->uri->uri_string())."?idioma=english",'&nbsp;', 'class="language" id="en"') ?></li>
    <li><?php echo anchor(($this->uri->uri_string())."?idioma=portuguese",'&nbsp;', 'class="language" id="pt"') ?></li>
    <li><?php echo anchor(($this->uri->uri_string())."?idioma=german",'&nbsp;', 'class="language" id="de"') ?></li>
    <li><?php echo anchor(($this->uri->uri_string())."?idioma=french",'&nbsp;', 'class="language" id="fr"') ?></li>
</ul>

And my construct from controller:

    $this->load->library('user_agent');
    if ($this->config->item('language') == '') {
        if($this->input->get('idioma') == true) {
            $this->config->set_item('language', $this->input->get('idioma'));
        } elseif ($this->agent->accept_lang('en')) {
            $this->config->set_item('language', 'english');
        } elseif ($this->agent->accept_lang('de')) {
            $this->config->set_item('language', 'german');
        } elseif ($this->agent->accept_lang('pt')) {
            $this->config->set_item('language', 'portuguese');
        } else {
            $this->config->set_item('language', 'portuguese');
        }
    }
    $language = $this->config->item('language');
    $data['language'] = $language;
    $this->load->vars($data);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:31:14+00:00Added an answer on June 13, 2026 at 10:31 pm

    First, I suggest to you make use of base_url() like:

    <script src="<?php echo base_url('assets/js/main.js') ?>"></script>
    

    Second, you are not able to use php code in javascript files as you are doing at main.js:

    var base_url = '<?php echo base_url(); ?>';
    var language = '<?php echo $language; ?>';
    

    One alternative is print the javascript variables before to main.js invocation:

    <script type="text/javascript">
        var base_url = '<?php echo base_url(); ?>';
        var language = '<?php echo $language; ?>';
    </script>
    
    <script src="<?php echo base_url('assets/js/main.js') ?>"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im having troubles with adding a class to the last option from foreach, its
I'm having troubles trying to find a solution, if any, to this: public class
I'm having some trouble sending along more than one variable to the view. my
I'm having troubles getting this to work. Basically I have a python program that
I am having trouble sending data on a socket from an iphone application I
I'm having trouble sending mail using SMTP from a Rails app. I have a
I am having trouble sending emails with PHP. Can you see any problems in
I'm having some trouble sending a file by ftp from my BizTalk 2006RC. The
I am having trouble sending email from my app at Google App Engine. I
I am currently using minimalistic Telnet from CodeProject and am having trouble sending the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.