javascript - Using json_encode without displaying it on my webpage via echo or print -
Basically I'm trying to pass a array of JavaScript from PHP, so far it's using all the methods I'm using. Are:
PHP:
echo json_encode ($ arrayname);
Javascript:
$ GetJSON ('myphppage.php', {}, function (data) {// here stuff here}};
Obviously, this is the text echo on my webpage, but this text Should not be shown, I'm just wondering if I have to use it for any purpose, without any firearms on my webpage (I tried it without echoing and it does not work, I also went to countless tutorials on it. But no one can do this without using echo)
Thanks long ago
---------- Edit -------------
index.js
$ GetJSON ('myphppage.php', {}, function (data) {// I loop through data here}}). (Function () {});
< / Pre>myphppage.php
& lt; php $ servername = "name"; $ Username = "user name"; $ Password = ""; $ Dbname = "dbname" ; $ Connection = mysql_connect ($ servername, $ username); if (! Connection!) {Die ("database connection failed:". Mysql_error ());} and {$ db_select = mysql_select_db ($ dbname, $ connection); if (! $ Db_select) {Dead ("Database selection failed:". Mysql_error ()); } $ Result = mysql_query ("Choose * FROM Tablename"); If (! $ Result) {echo 'query could not be run:' mysql_error (); Go out; } $ Array = array (); While ($ line = mysql_fetch_array ($ result)) {array_push ($ array, $ line); } Echo json_encode ($ array); }
minimum example:
index.html
$ GetJSON ('myphppage.php', {}, function (data) {// here content here});
myphpwebpage.php
echo json_encode ($ arrayname);