Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28773 > unrolled thread
| Started by | JiiPee <no@notvalid.com> |
|---|---|
| First post | 2015-10-02 00:13 +0100 |
| Last post | 2015-10-02 20:29 +0200 |
| Articles | 13 on this page of 33 — 7 participants |
Back to article view | Back to comp.lang.javascript
How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 00:13 +0100
Re: How to pass a php variable to a javascript file (function)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 09:44 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-02 12:14 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:43 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:58 +0100
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-02 13:38 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 12:53 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 13:46 +0100
Re: How to pass a php variable to a javascript file (function)? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-02 13:51 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-02 21:42 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-03 00:33 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 23:45 +0100
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-02 23:55 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-03 00:02 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 23:49 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-02 21:37 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-03 00:34 +0200
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 04:35 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-05 01:11 +0200
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-05 09:13 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-06 03:30 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-10 00:27 +0200
Re: How to pass a php variable to a javascript file (function)? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-10-03 15:15 -0300
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 20:34 +0200
Re: How to pass a php variable to a javascript file (function)? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-10-03 15:59 -0300
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 22:15 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:36 +0100
Re: How to pass a php variable to a javascript file (function)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 16:34 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 16:00 +0100
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-02 16:03 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 17:08 +0100
solution, thanks, seems like one suggestion lead to a solution JiiPee <no@notvalid.com> - 2015-10-02 17:07 +0100
Re: solution, thanks, seems like one suggestion lead to a solution "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 20:29 +0200
Page 2 of 2 — ← Prev page 1 [2]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-10-06 03:30 +0200 |
| Message-ID | <3467116.VtDcax7U2a@PointedEars.de> |
| In reply to | #28811 |
Stefan Weiss wrote:
> On 2015-10-03 04:35, Thomas 'PointedEars' Lahn wrote:
>> Stefan Weiss wrote:
>>> I wrote (quoted) that "<script" should be replaced with
>>> "<\script".
>> This assertion is in the same sense wrong as is the following one further
>> below the Specification prose, in another note:
>
> [ snip spec note ]
>
>> The problem here is that the authors make the common mistake
>> and use the term “JavaScript” as an umbrella term, failing to
>> differentiate between ECMAScript implementations.
>
> Oh, here we go again... Don't you ever get tired of this?
I never get tired of the telling people the truth that virtually jumps in
your face out of my more than a decade of in-depth experience with the
topic, and the results of my research. If only you would find it within
yourself to see it, you could make *real* progress.
>>> str_replace("<script", "<\script", $some_text);
>>>
>>> Done.
>> No.
>
> ...because? A simple unqualified "no" is not good enough.
Read further below.
>> (And it is bad practice to use unknown escapes in double-quoted string
>> literals in PHP.
>
> "\s" is not an unknown escape,
But it is, in *string* literals. “\” starts an escape sequence in PHP and
ECMAScript. Because the escape sequence is unknown – better: *not
defined* – in *string* literals, there is a fallback and it is parsed
verbatim. That is also why "<\/…>" works in ECMAScript for escaping both
ETAGO delimiters and end-tags of “script” elements.
<http://www.ecma-international.org/ecma-262/6.0/index.html#sec-static-semantics-sv>
| […]
| · The SV [String value; the ed.] of CharacterEscapeSequence ::
| NonEscapeCharacter is the SV of the NonEscapeCharacter.
| · The SV of NonEscapeCharacter :: SourceCharacter but not one of
| EscapeCharacter or LineTerminator is the UTF16Encoding (10.1.1) of the
| code point value of SourceCharacter.
| […]
> it's two characters. If this offends your eyes, or you're not sure what i
> an what isn't an escape sequence in a PHP string,
This is not about my preferences or knowledge, it is about future-proof
coding.
> you're free to use "\\s" or '\s'. The result is the same.
Which proves my point as "\\" is the *known* – better: *defined* – escape
sequence for the backslash character in both ECMAScript and PHP. Whereas in
ECMAScript, “\s” is not defined in string literals, but in RegExp literals,
and therefore “\\s” in string literals that are arguments for the RegExp
constructor; and in PHP, different to “\s”, “\\” is defined in *both*
single-quoted and double-quoted string literals.
<http://php.net/manual/en/language.types.string.php>
>> It is also unwise to use double-quoted string literals where single-
>> quoted string literals would have sufficed, because different to
>> ECMAScript, double quotes also imply interpolation in PHP [and several
>> other script languages].)
>
> Thanks for the lecture, but I'm well aware of how PHP strings work.
Evidentially you are not.
> The single vs double quote issue has been discussed ad nauseam, and what
> it always boils down to is that it's primarily a matter of preference […]
Only to the superficial and self-deluded. The discussions you are referring
to are about runtime efficiency instead. But that is not the only criterion
for good code.
>>> And even *IF* it was a Perl regex (which is a completely random
>>> and off-topic assumption), the "\s" is in the replacement part, not in
>>> the matching part.
>> I was talking about code that can be (but does not have to be) contained
>> in markup, code that uses regular expressions to match and process
>> markup. That code will be broken by blind escaping to accomodate HTML
>> parsers.
>
> Then you're talking about something nobody asked.
You are mistaken.
> This is not about escaping code, it's about escaping the contents of a
> string in a <script> element.
No, the knee-jerk assertion in the HTML Specification note (in fact, the
requirement in this case) is to escape or avoid *all* offending code in a
“script” element¹. For an HTML parser makes no difference whether the
offending code is in a string literal; it does not (need to) know about
string literals in embedded, non-HTML code.
Further, the contents of a (string in a) “script” element *is* (source)
code, and it can be code that contains expressions like such literals.
Where such blindfolded escaping *can* change the meaning of the code.
________
¹ Although unfortunately common, it is wrong to write “<script>” etc. in
that regard; “<script>” is only the start-tag of the “script” element,
and only a particular variant of it.
>> Interesting. As for Chromium 44.0.2403.89 on GNU/Linux, for which I can
>> confirm that unescaped “</script>” in a “script” element is a problem,
>> this should be considered a bug as (AFAICS) the given ABNF for the
>> “script” element content allows “</script>” in it.
>
> It's not just Chrome, you get the exact same behavior in Firefox and
> IE/Edge. […]
I have not doubted that, which you could have read further below.
Superficial reading appears to be the major cause of your misconceptions.
>>> To get a valid XML document, you'll have to escape much more than the
>>> strings I mentioned.
>>
>> No, as I have said many times before in both in
>> <news:de.comp.lang.javascript> and here, you just have to declare the
>> offending “script” element content a part of a CDATA section
>
> Then that's a completely different context.
No, we are still talking about XHTML documents, in particular about XHTML
“script” elements. You have claimed just before (for *everyone* to read)
that “much more than the strings [you] have mentioned” would need to be
escaped in the contents of XHTML “script” elements.
That claim is incorrect. XHTML as an application of XML provides other
means to ensure that source code is not misinterpreted as markup, namely
marking up offending source code as CDATA.
> You obviously have to use different escaping in a CDATA section...
Can’t you read? CDATA sections make it *unnecessary* to do *most* of the
escaping for Valid *and* working markup. But one should trigger the
appropriate (XHTML) parser as well.
And that is the crux of the matter, that eventually leads to the conclusion
that it is easier and safer to *not* embed code in “script” elements in the
first place.
>> // escape “]]>” here if “<” follows
>
> ... but not like that!
Well, it is rather difficult to give a description of the CDATA section end
marker in a comment without mentioning it. If you can live better with
that, replace the line in the example with
// escape the CDATA section end marker here if “<“ follows
where you can see (by testing it) that the markup character “<” is ignored
by an XHTML/XML parser *because* it is contained in a CDATA section. The
same applies to “</script>” then, so, contrary to what you claimed, it does
*not* need to be escaped then.
>> But none of this is necessary, regardless of the document type, if you
>> move the “script” element content to a separate file, and use the “src”
>> attribute, AISB.
>
> Correct but off-topic.
Nonsense. The topic of this newsgroup is ECMAScript-based programming,
primarily in Web browsers, and the subject of this thread is how to use
ECMAScript-based code in HTML properly and easily.
The correct answer is that, not least because of the difficulties of
embedding ECMAScript-based code in (X)HTML “script” elements, it is for
several good reasons (which have been named before, but I can repeat them if
necessary) better to include it using the “src” attribute of the “script”
element instead. *Contrary to* what the authors of the HTML5 Specification
recommend in their *non-normative* notes.
> > IOW: Your logic is flawed. You should learn to control your emotions
> > lest they control you.
>
> Somebody's taking their science fiction a little too seriously.
Or perhaps the message is more important than the man?
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2015-10-10 00:27 +0200 |
| Message-ID | <mv9f0r$5p9$1@news.albasani.net> |
| In reply to | #28813 |
In the interest of brevity, and my own sanity, I chose not to respond to
the following parts of your post:
- The lengthy excursion about PHP coding style. It has nothing to do
with the topic. Use whatever style of quoting and escaping you prefer.
- That embedded script content in an XML document should be in a CDATA
section. We're in agreement there. To simply _assume_ that we are in a
CDATA context when we were talking about escaping was a little
underhanded, but since we agree about the main point, let it rest.
- Further evangelizing the use of linked scripts vs inline scripts.
Preaching to the choir. I agree. But this is NOT what we're talking
about here, it merely provides an alternative.
- Spockisms.
On 2015-10-06 03:30, Thomas 'PointedEars' Lahn wrote:
>>>> str_replace("<script", "<\script", $some_text);
>>>>
>>>> Done.
>>> No.
>> ...because? A simple unqualified "no" is not good enough.
> Read further below.
I read everything you wrote "further below", but you still failed to
demonstrate how this method of escaping could be harmful. Give an
example or concede the argument.
>> This is not about escaping code, it's about escaping the contents of a
>> string in a <script> element.
>
> No, the knee-jerk assertion in the HTML Specification note (in fact, the
> requirement in this case) is to escape or avoid *all* offending code in a
> “script” element¹. For an HTML parser makes no difference whether the
> offending code is in a string literal; it does not (need to) know about
> string literals in embedded, non-HTML code.
You're getting sidetracked by the examples in the specification again.
You keep bringing up all kinds of contexts except the one we were
originally discussing: transferring a PHP string value to a JS string
literal in an embedded script in an HTML document.
> Further, the contents of a (string in a) “script” element *is* (source)
> code, and it can be code that contains expressions like such literals.
> Where such blindfolded escaping *can* change the meaning of the code.
You get no points for just claiming that, without proof.
[referring to where I wrote "a <script> element"]
> ¹ Although unfortunately common, it is wrong to write “<script>” etc. in
> that regard; “<script>” is only the start-tag of the “script” element,
> and only a particular variant of it.
You know... if you're ever wondering why they're calling you a pedant,
*that* is precisely the reason. In the same vein, you'll probably object
to somebody mentioning the sprintf() function - because it's really the
“sprintf” function? Stop trying to distract with nitpicks and inane
overcorrections and get to the point.
>> It's not just Chrome, you get the exact same behavior in Firefox and
>> IE/Edge. […]
>
> I have not doubted that, which you could have read further below.
> Superficial reading appears to be the major cause of your misconceptions.
Maybe you're just not communicating very well. Reading this passage
again, I still cannot identify what exactly you're referring to as
"further below". Not that it matters.
>>> // escape “]]>” here if “<” follows
>>
>> ... but not like that!
>
> Well, it is rather difficult to give a description of the CDATA section end
> marker in a comment without mentioning it.
...
> If you can live better with that, replace the line in the example with
>
> // escape the CDATA section end marker here if “<“ follows
You completely missed the point. I wasn't criticizing the
well-formedness of your example, that would be ridiculous. I was talking
about its actual content - what to escape, and when:
<script type="text/javascript">// <![CDATA[
console.log("This is ]]> just a string.");
// ]]></script>
This follows your described escaping rule and leads to a ruined XML
document. See, an actual example. How hard is that?
Looking forward to seeing one from you.
- stefan
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2015-10-03 15:15 -0300 |
| Message-ID | <mup60b$d1a$1@speranza.aioe.org> |
| In reply to | #28795 |
Thomas 'PointedEars' Lahn wrote: > Stefan Weiss wrote: > >> On 2015-10-02 09:44, Evertjan. wrote: >>>> var some_string = <?php echo json_encode($sometext); ?>; >>> >>> This is totally errorprone, you need to enclose the litteral string in >>> '-s or "-s, ensuring that the ones used do not appear in the inner text. >> >> No, json_encode() already takes care of quoting and character escaping; >> adding extra quotes around the result would be a syntax error. > > ACK. It seems the FAQ needs an update with this information. 11.3 How do I get a jsp/php variable into client-side javascript? <http://pointedears.de/scripts/faq/cljs/#getServerVariable> >>> >>> Why don't you create that string on the "index.html" PAGE, >>> that you probably will have to rename to "index.php". >> >> Thats one way to do it. Unfortunately, we don't know enough about OP's >> project to give any meaningful advice. For example, if we knew that >> `some_string` is relatively short, we could suggest passing it along to >> index.html in the query string. >> >> location.href = "index.html?s=" + encodeURIComponent(some_string); >> >> The script included from index.html could then read it back from the >> query string. > > It is important to emphasize “relatively short”, because this approach is > subject to IE URL length limits which can be easily exceeded if the argument > to encodeURIComponent() contains Unicode characters with code points beyond > the US-ASCII range (as URI percent-encoding is UTF-8 based). I wouldn't say it is easy to exceed the 2083 characters limit in IE, which applies to older versions. Also there are different URL length limits for bookmarks and IFRAMES in IE too. See: <http://blogs.msdn.com/b/ieinternals/archive/2014/08/13/url-length-limits-in-internet-explorer.aspx> -- Joao Rodrigues
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-10-03 20:34 +0200 |
| Message-ID | <2001160.vPYRIAvtoo@PointedEars.de> |
| In reply to | #28806 |
Joao Rodrigues wrote: > Thomas 'PointedEars' Lahn wrote: >> Stefan Weiss wrote: >>> […] if we knew that `some_string` is relatively short, we could suggest >>> passing it along to index.html in the query string. >>> >>> location.href = "index.html?s=" + encodeURIComponent(some_string); >>> >>> […] >> >> It is important to emphasize “relatively short”, because this approach is >> subject to IE URL length limits which can be easily exceeded if the >> argument to encodeURIComponent() contains Unicode characters with code >> points beyond the US-ASCII range (as URI percent-encoding is UTF-8 >> based). > > I wouldn't say it is easy to exceed the 2083 characters limit in IE, > which applies to older versions. […] You are misinformed. See <http://stackoverflow.com/a/417184/855543> pp. for details. -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2015-10-03 15:59 -0300 |
| Message-ID | <mup8iu$im9$1@speranza.aioe.org> |
| In reply to | #28807 |
Thomas 'PointedEars' Lahn wrote: > Joao Rodrigues wrote: > >> Thomas 'PointedEars' Lahn wrote: >>> Stefan Weiss wrote: >>>> […] if we knew that `some_string` is relatively short, we could suggest >>>> passing it along to index.html in the query string. >>>> >>>> location.href = "index.html?s=" + encodeURIComponent(some_string); >>>> >>>> […] >>> >>> It is important to emphasize “relatively short”, because this approach is >>> subject to IE URL length limits which can be easily exceeded if the >>> argument to encodeURIComponent() contains Unicode characters with code >>> points beyond the US-ASCII range (as URI percent-encoding is UTF-8 >>> based). >> >> I wouldn't say it is easy to exceed the 2083 characters limit in IE, >> which applies to older versions. […] > > You are misinformed. > > See <http://stackoverflow.com/a/417184/855543> pp. for details. > Don't believe in a guy who writes: "IE8's maximum URL length is 2083 chars, and it seems IE9 has a similar limit." MSDN has the correct answers. -- Joao Rodrigues
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-10-03 22:15 +0200 |
| Message-ID | <9085221.OgTPPyc7mI@PointedEars.de> |
| In reply to | #28809 |
Joao Rodrigues wrote: > Thomas 'PointedEars' Lahn wrote: >> Joao Rodrigues wrote: >>> I wouldn't say it is easy to exceed the 2083 characters limit in IE, >>> which applies to older versions. […] >> >> You are misinformed. >> >> See <http://stackoverflow.com/a/417184/855543> pp. for details. > > Don't believe in a guy who writes: "IE8's maximum URL length is 2083 > chars, and it seems IE9 has a similar limit." > > MSDN has the correct answers. Read the comments. Do the tests. Post the results. -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | JiiPee <no@notvalid.com> |
|---|---|
| Date | 2015-10-02 11:36 +0100 |
| Message-ID | <t6tPx.25818$8%3.15388@fx31.am4> |
| In reply to | #28775 |
On 02/10/2015 08:44, Evertjan. wrote:
>> <script type="text/javascript">
>> function doIt() {
> This does not work, as doIt() is not called clientside.
What do you mean by "does not work"? I have this code and it does open
the index.html when this doIt is called. The purpose of doIt is to
prepare a string (some_string) and then open index.html. And index.html
contains js code and the purpose is that this js could somehow use this
some_string content. yes its a local variable here and is deleted, but I
mean we could pass it or put on some global variable to used it later in
that javascript file. Thats the purpose...
>
>> var some_string = <?php echo json_encode($sometext); ?>;
> This is totally errorprone, you need to enclose the litteral string in '-s
> or "-s, ensuring that the ones used do not appear in the inner text.
yes true.
>
> Have a look houw the resulting stream looks on the client-browser using
> view-source.
>
>> window.location.href = encodeURI("index.html");
> There is no need to encodeURI() "index.html"'
well, there was other code there as well, like variables, so I needed
that encode.... but yes not here is needed.
>
> If[!] doIt() is run then the clientside variable some_string is lost.
>
yes, but the question is that where can we save that some_string (or
pass it?) so that later on some javascript file could us it. Is a good
idea to pass it to index.html somehow and from there to that javascript
file?
>> Then this html site calls javascript
>> function from a js-file:
> No.
>
> html-PAGES do not CALL javascript files,
> they could include code to include a js-file.
yes and that code calls a js function. thats what happens
>
>> test.js :
>>
>> function doSomething() {
>> // here I want to use that some_string created in the php file....
>> }
> That variable some_string, being a clientside javascript varaiable on
> another PAGE, was lost when leaving that page.
yes, but can we save it somehow somewhere to be able to use here?? thats
the question. or can we have some route to pass it all the way here from
there?
>
>> So in doSomething I want to be able to use this some_string created in
>> php file. How can I do it?
> So you cannot.
>
> Why don't you create that string on the "index.html" PAGE,
hmmm, yes i could possibly create it in that index.html (although to
create it i need php code... but I guess its doable in html file....
surely) page (as I can pass information to that file from that php file
to form that string). But how could this help?
> that you probably will have to rename to "index.php".
yes, that is a good idea.... at least to try. and migh work for me...
but index.html is quite big file I think, i hope the change happens
without problems. I can try....
>
> I tried couple of things, but I do not really
>> understand Ajax...
> There is no mention of Ajax here, only of some lost serverside json-code.
not here , but I tried Ajax elsewhere
> :) ?
>
> Being a newbie is no joke, it is and should be hard.
>
> Seems to me you need to explain what you want in a better way.
>
> Programming primarily is about describing what you want to yourself in a
> logical way, not copying code from the web you do not understand and
> expecting it to do what you have not visualized.
so far I pretty much understand what is happening and the sites work ok
. But am a bit stuck with this one. I can pass php variables to js code
in a same file, no problems.
>
> And remember, only Javascript is on topic here, either clientside or
> serverside, php is not.
ok but those languages are very much linked in real life....
>> Re: How to pass a php variable to a javascript file (function)?
> Seems you were talking about a clientside Javascript variable here,
I have php file with contains this js code which creates this variable I
want to forward to other javascript files:
php-file:
- contains a js-code which creates a js variable (and/or php variable...
does not matter)
index.html:
- php-file opens this
- this file contains a js code/fucntion which is located in a separate
js-file
js-file:
here, in one function, I want to get hold of that string which was
created in php file above.
> those variables are only valid as long as the PAGE exists,
> they do not exist on the [serverside] SITE.
>
> Your "javascript file" surely exists on the server, so including something
> there needs serverside scripting. You could howeve include something in the
> stream that is sent to the client using php when renaming the js file to:
> "myJSfile.js.php".
>
ok thanks, at least I can try your idea of changing that index.html to
php... maybe it works...
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-10-02 16:34 +0200 |
| Message-ID | <XnsA527A8A801690eejj99@194.109.6.166> |
| In reply to | #28778 |
JiiPee <no@notvalid.com> wrote on 02 Oct 2015 in comp.lang.javascript:
> On 02/10/2015 08:44, Evertjan. wrote:
>>> <script type="text/javascript">
>>> function doIt() {
>> This does not work, as doIt() is not called clientside.
>
> What do you mean by "does not work"? I have this code and it does open
> the index.html when this doIt is called.
That is the key: "when this doIt is called"!
Please do not let us assume.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | JiiPee <no@notvalid.com> |
|---|---|
| Date | 2015-10-02 16:00 +0100 |
| Message-ID | <d_wPx.67915$oH6.19678@fx36.am4> |
| In reply to | #28787 |
On 02/10/2015 15:34, Evertjan. wrote:
> JiiPee <no@notvalid.com> wrote on 02 Oct 2015 in comp.lang.javascript:
>
>> On 02/10/2015 08:44, Evertjan. wrote:
>>>> <script type="text/javascript">
>>>> function doIt() {
>>> This does not work, as doIt() is not called clientside.
>> What do you mean by "does not work"? I have this code and it does open
>> the index.html when this doIt is called.
> That is the key: "when this doIt is called"!
>
> Please do not let us assume.
>
for example when a user presses a button. then it goes to doIt().
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2015-10-02 16:03 +0100 |
| Message-ID | <021020151603470265%timstreater@greenbee.net> |
| In reply to | #28788 |
In article <d_wPx.67915$oH6.19678@fx36.am4>, JiiPee <no@notvalid.com>
wrote:
>On 02/10/2015 15:34, Evertjan. wrote:
>> JiiPee <no@notvalid.com> wrote on 02 Oct 2015 in comp.lang.javascript:
>>
>>> On 02/10/2015 08:44, Evertjan. wrote:
>>>>> <script type="text/javascript">
>>>>> function doIt() {
>>>> This does not work, as doIt() is not called clientside.
>>> What do you mean by "does not work"? I have this code and it does open
>>> the index.html when this doIt is called.
>> That is the key: "when this doIt is called"!
>>
>> Please do not let us assume.
>for example when a user presses a button. then it goes to doIt().
If you want a simple ajax example BTW, see:
http://www.clothears.org.uk
--
Lady Astor: "If you were my husband I'd give you poison." Churchill: "If
you were my wife, I'd drink it."
[toc] | [prev] | [next] | [standalone]
| From | JiiPee <no@notvalid.com> |
|---|---|
| Date | 2015-10-02 17:08 +0100 |
| Message-ID | <ZZxPx.24465$436.19712@fx13.am4> |
| In reply to | #28789 |
On 02/10/2015 16:03, Tim Streater wrote: > In article <d_wPx.67915$oH6.19678@fx36.am4>, JiiPee <no@notvalid.com> > >> for example when a user presses a button. then it goes to doIt(). > > If you want a simple ajax example BTW, see: > > http://www.clothears.org.uk > ok thanks. looks good
[toc] | [prev] | [next] | [standalone]
| From | JiiPee <no@notvalid.com> |
|---|---|
| Date | 2015-10-02 17:07 +0100 |
| Subject | solution, thanks, seems like one suggestion lead to a solution |
| Message-ID | <ZYxPx.24464$436.6665@fx13.am4> |
| In reply to | #28773 |
somebody suggested changing my html file to a php file which would make it easy to send data from the first php file. And that seems to do the trick... I was able to change it and it still works like before. So this seems to be a solution for now. and yes, its easy to contact from php file to to a js-file...and pass my string like this. seems to work (using a global js variable.)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-10-02 20:29 +0200 |
| Subject | Re: solution, thanks, seems like one suggestion lead to a solution |
| Message-ID | <XnsA527D064B93Beejj99@194.109.6.166> |
| In reply to | #28792 |
JiiPee <no@notvalid.com> wrote on 02 Oct 2015 in comp.lang.javascript: > somebody Seems decent to quote that, perhaps it was me. > suggested changing my html file to a php file which would make > it easy to send data from the first php file. And that seems to do the > trick... I was able to change it and it still works like before. So this > seems to be a solution for now. > > and yes, its easy to contact from php file to to a js-file... You can also use a php-file as a js file, thereby adding all the serverside coding functionality to that file. <script type='text/javascript' src='myJsFile.php'></script> > and pass my > string like this. seems to work (using a global js variable.) No, a clientside "global js variable" is only valid in a single page, so I do not see why tht even is needed. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web