Welcome Guest, Not a member yet? Register   Sign In
Need help passing a variable to an external javascript file embedded in a view
#1

[eluser]chamilyan[/eluser]
I am loading a view from a controller with a data array. I need to pass a variable from the data array to a javascript file called by my view page. I can reference the .JS file however the context does not allow me to send any of the data variables to it. How can I do this easily without tooo much more hacking? I don't want to use query strings but I have
Code:
$config['allow_get_array']= TRUE;
enabled.

Here is what I'm currently doing to refer to the javascript (jQuery) file in my view. As you can see I'm attempting to append a hash and refer to my variable that way, but this isn't working. I'm pretty sure there is an easier, less hacky way to do this anyways.

in the controller:
Code:
$data = array('name' => $userid);
$this->load->view('fb', $data);

in the view:
Code:
[removed][removed]
<?php $JSurl = site_url('../JS/js.php').'#'.$name;?>
[removed][removed]

in the JS file:
Code:
<?php header('Content-type: text/javascript');?>
$(document).ready(function() { //start document ready
alert(this.hash);
}); //end document ready

I'm echoing the Jquery library on the top part and $JSurl within J-SCRIPT tags in the [removed] code portions, not sure why they wouldn't post.


Messages In This Thread
Need help passing a variable to an external javascript file embedded in a view - by El Forum - 07-28-2011, 05:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB