How create a JavaScript file with a view in CodeIgniter? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How create a JavaScript file with a view in CodeIgniter? (/showthread.php?tid=20742) Pages:
1
2
|
How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]ivarsmas[/eluser] Hello everyone, I have to create a js dynamically file (calling a database and getting values) with CI and i don't know how, if i use a view the result is a php file, but I need to make this a js file, because i must be embed it on other pages. I have searched in this board and haven't find information. Any suggestion? Thanks!! How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] I'm not sure what you mean exactly, but if you need to use your PHP retrieved values in a JS script, then you can just do this: Code: [script type="text/javascript"] This will give you access to your php assigned vars inside of your JS code. (js should be <> not [] How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]devbro[/eluser] what about ajax? if you decided to go this way, you should right a special view file that spit outs the correct type of output that ajax expects (plain text, xml, ...) How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] No, I don't think that is the case at all. For adding ajax, just populate your variables before load your customer tool, and build a controller to handing ajax calls. I usualy just use ajax.php for the controller, and build my methods in there. How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]ivarsmas[/eluser] Thanks techneke, but maybe I have not explained well. :-S I need create a JavaScript file with a ".js" extension, but with the "views of CodeIgniter" only is possible output a result without extension and executed in own server. With a CI view now i get: http://www.domain.com/order And i want get: http://www.domain.com/order/js_file_name.js?id=11111 (o similar..) and changing his content by calling to database with this id passed. For i can to give to users this js file, to embed this in his sites once created. And execute it in navigator of user. It is better explained now? How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] first of all, why are you passing things into js that way? Bad Practice.. Second, then call it like this [script type="text/javascript" src="<?= base_url(); ?>js/jsfile.js?id=<?= $what_ever_php_var; ?>"][/script] How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]ivarsmas[/eluser] The problem isn't calling to javascript, else to create the file with js extension how output in CodeIgniter. How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] There is no reason to build a JavaScript file in that way. I'd highly recommend rethinking the way you're executing your project. How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]davidbehler[/eluser] Lets say you have a controller called "js" and a function "get" Code: class js extends Controller Now you can include the file using Code: [script type='text/javascript” src=”<?=site_url('js/get/123');?>”][/script] How create a JavaScript file with a view in CodeIgniter? - El Forum - 07-20-2009 [eluser]Zack Kitzmiller[/eluser] You'd have to do some routes stuff with that kind of execution, some browers will choke on not having a .js extension. Even with the correct header. |