Note that there are some explanatory texts on larger screens.

plurals
  1. POPass value to PHP file using JavaScript and receive new set of values from PHP to JavaScript and display in Browser
    primarykey
    data
    text
    <ol> <li>I have a page called test.html. This HTML page will contain 2 JavaScripts file. I need to pass a variable value to a PHP file using the first JavaScript file. The user can copy this javascript on as many pages as he wants for displaying output.</li> <li>The PHP file that receives the variable from the JavaScript file retrieves some data from database depending upon the variable's value. This retrieved value can contain HTML content. This PHP file will always reside on my server.</li> <li>All of the retrieved content (from the PHP file) needs to be passed to the second JavaScript file so that the data can be displayed in browser. This JS file will need to stay together with the first JS file in order for the data to be displayed.</li> </ol> <p><em><strong>So I have this:</em></strong></p> <p><strong>JavaScript File</strong></p> <pre><code>&lt;script type= "text/javascript" src="http://www.myserver.com/custom_script.php?unique_id=12"&gt;&lt;/script&gt; </code></pre> <p><strong>PHP FILE</strong></p> <pre><code>//custom_script.php &lt;?php $unique_id= (int)$_GET['unique_id']; $res = db_res(" SELECT col1, col2, col3, .... col10 FROM table WHERE unique_id = $unique_id LIMIT 1 "); $rows = mysql_fetch_array($res); ?&gt; &lt;div id="1"&gt;&lt;?php echo $rows['col1']; ?&gt;&lt;/div&gt; &lt;div id="2"&gt;&lt;?php echo $rows['col2']; ?&gt;&lt;/div&gt; &lt;div id="3"&gt;&lt;?php echo $rows['col3']; ?&gt;&lt;/div&gt; . . . &lt;div id="10"&gt;&lt;?php echo $rows['col10']; ?&gt;&lt;/div&gt; </code></pre> <p>I need to send all the HTML above from the PHP file to the second JavaScript file so that the output can be displayed. Please note that the CSS styling is also applied using Div ID, so I am expecting those styles would show up too. Please note that there may be more than 10 columns, so an efficient way of passing data is highly appreciated.</p> <p>So what would be the easiest and the best way to send all the HTML data from the PHP file in one go to the 2nd javascript file residing in test.html page, so that the HTML data can be displayed in test.html file?</p> <p><strong>EDIT 1:</strong></p> <p>I apologize to everyone if my question has been confusing. I just thought of an example and hence wanted to add it my edit. I hope you are all aware of what Google Analytics (GA)(or any other Website Visits Stats Tracker) does. Right? You register for a Analytics account and Google gives you a piece of JS code that you copy and paste in your website. And after couple of days, you can login into your GA account to see the stats. Correct? What I am trying to do here is just the same. </p> <p>Users come to MY WEBSITE and register for an account and I give them JS files that they can paste in their website. The only difference between GA and my website is that GA is personal to you and no one else, but you, the account holder can see it. Whereas in my case, your data can BE SEEN by others as well, as long as you include the JS file on your website. Because users can't just take my PHP file and run it on their server, I am trying to access MY PHP file by giving the full path to it in the JS file. </p> <p><strong>For example:</strong></p> <p><code>&lt;script type= "text/javascript" src="http://www.myserver.com/custom_script.php?unique_id=12"&gt;&lt;/script&gt;</code></p> <p>This is not an actual JS file, rather it is just a medium for my custom_script.php script to receive the unique_id of the user, query MY database and send back the HTML data related to this requesting user. And I am stuck with this part. Hope this clairifies what I am trying to do.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload