Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: How to pass a php variable to a javascript file (function)? Date: Fri, 02 Oct 2015 21:42:13 +0200 Organization: PointedEars Software (PES) Lines: 31 Message-ID: <1624850.oZzQaDyhdP@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1443814933 31066 eJwFwYEBwDAEBMCVin9iHET2H6F3NBefgNPBx7ctWXZnkApSgWuLHab2uV6fhObmaa3g7P4d6RE5 (2 Oct 2015 19:42:13 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 2 Oct 2015 19:42:13 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNxcEBwCAIA8CVJE1AxwGV/Uew9zl9br6DLqdajYuNm/gH56zCqNPu5FqZyHHuyZI8VWBbWxiDKyDOgh5ZxBUg Cancel-Lock: sha1:kCMFI3qLcMgK8DsysSveclrkoyw= X-NNTP-Posting-Host: eJwNy8ENwEAIA8GWgsA+2onJuf8Swm810iIZnFMEC4YfLPienMiajy2/XdqKkSkE2zv0laLcPyD7EZk= Xref: csiph.com comp.lang.javascript:28796 Stefan Weiss wrote: > On 2015-10-02 12:58, JiiPee wrote: >> I guess my main question is that if I have a php file how can I send >> data/string from there to a javascript file. >> >> php file: >> contains some data/string >> >> test.js file: >> wants to get hold of that string created in php file > > Ah. Now that the navigation is out of the way, it's simple enough. > test.js has access to the same variables as any inline script in the > document. You can make some_string a global variable; local variables in > functions are never visible outside the function. You can do that, but it is not a good idea to do it. In fact, this is bad advice. There should be as few global variables as possible. Whenever data needs to be available globally, *one* global variable which stores a reference to a native user-defined object should serve as the hub for storing data as values of the properties of that object. The value of the variable or the values of the properties of the referred object, should be passed to and between functions. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.