Hi, I search google, the general consensus is that php will not work in script tag, I accept that.
but than I came across this SO forum [url]http://stackoverflow.com/questions/8310227/using-php-in-script-tag[/url] , they seem to say that with proper form it will wor, what gives?
@NogDogFeb 02.2017 — #Depends on what you mean by "PHP in script tag." Actual PHP code will not execute within JavaScript itself [I]on the browser[/I], but you can use PHP on the server side to create/modify the JavaScript code that will be run once the page gets to the browser: [code=php] <script type="text/javascript"> <?php echo 'alert("Hello there.");'; ?> </script> [/code]
@rootFeb 02.2017 — #Having looked at the link, they are looking at making the JavaScript equivalent code in JavaScript, it is not PHP in script tags, its still JavaScript and mostly the examples are JQuery which is not JavaScript in any case, JQuery is a framework (toolkit) written in JavaScript.
Confused? Many people confuse JQuery and similar as being JavaScript.
@rich1812authorFeb 03.2017 — #Having looked at the link, they are looking at making the JavaScript equivalent code in JavaScript, it is not PHP in script tags, its still JavaScript and mostly the examples are JQuery which is not JavaScript in any case, JQuery is a framework (toolkit) written in JavaScript.
Confused? Many people confuse JQuery and similar as being JavaScript.[/QUOTE]
"Confused?" LOL, Confused is the under statement! ? to say the least.
@NogDogFeb 03.2017 — #Well...jQuery is still JavaScript, just like Rails is still Ruby, and Laravel is still PHP. jQuery is written in JavaScript, and you use JavaScript code to make use of it -- but it's still all JavaScript.
@rootFeb 06.2017 — #Its not that hard, PHP runs on the web server (AKA server-side), JavaScript runs in the web browser (AKA Client-side)
PHP is its own programming language for server-side that allows your to dynamically create HTML and also incorporate a database. (PHP is one of several server side programming languages you can use, it happesn to be fairly popular and well supported)
JavaScript is a client side that is native to the web browser and allows you to manipulate the HTML DOM tree, perform some client to server interaction via a suitable PHP script (or similar)
JQuery is written in JavaScript, therefore it is not JavaScript because JQuery won't run in the web browser because it requires an additional resource to be loaded before it can be used.
People also confuse AJAX for JQuery, it again is a native element of JavaScript.
@NogDogFeb 06.2017 — #...JQuery is written in JavaScript, therefore it is not JavaScript because JQuery won't run in the web browser because it requires an additional resource to be loaded before it can be used....[/QUOTE]
And that additional resource is...a JavaScript file(s).
@rootFeb 07.2017 — #And that additional resource is...a JavaScript file(s).[/QUOTE]
Exactly, you can't run JQuery without loading the framework that is written using JavaScript, the point being that (to kkep it simple) JavaScript scripts run instantly in the browser when the HTML has loaded where as you have to wait for JQuery file to load, then your JQuery to load before it can run and the JQuery framework, even when minimised is fairly substantial in size and adds allot of bloat and weight to the site codebase.
I am aware that JQuery does on occasion resolve some cross browser issues, these issues wouldn't exist if browser development teams wouldn't have their heads up their own and work together to make their developments more standardized...