{"id":1351,"date":"2022-08-30T15:15:48","date_gmt":"2022-08-30T15:15:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/13\/use-php-var-in-javascript-file-fault-duplicate-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:48","modified_gmt":"2022-08-30T15:15:48","slug":"use-php-var-in-javascript-file-fault-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/use-php-var-in-javascript-file-fault-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"Use php var in javascript file fault [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p>I have a question about using a php variable in my javascript file. This is my <strong>index.php<\/strong> file:<\/p>\n<pre><code>\n    \n        \n            \n                \n                <br id=\"errors\" class=\"text-error\" \/><br \/><br \/>\n            \n        \n\n        \n\n     \n\n    \n    window.jQuery || document.write('')\n\n    \n\n    \n    \n\n<\/code><\/pre>\n<p>As you can see I check if an appid is sent. When I received it I load data from an api. In the bottom of the page I have a link to my javascript file. (.php because I want to use the php var $ array in my js file)<\/p>\n<p>My <strong>main.js.php<\/strong>:<\/p>\n<pre><code>$(document).ready(function() {\n    var data = ;\n    alert(data);\n});\n<\/code><\/pre>\n<p>But I got always error in console:<\/p>\n<blockquote>\n<p>Uncaught SyntaxError: Unexpected token<\/p>\n<\/blockquote>\n<p id=\"rop\"><small>Originally posted 2013-11-13 09:48:57. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a question about using a php variable in my javascript file. This is my index.php file: window.jQuery || document.write(&#8221;) As you can see I check if an appid is sent. When I received it I load data from an api. In the bottom of the page I have a link to my javascript [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1351","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1351"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1351\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}