JavaScript Pass and print a $_GET variable through php load file by javascript

I searched for a solution of passing a get variable obtained from index.php page to included.php file[ loaded by javascript ]. A nice solution by php require function is given Pass and print a $_GET variable through an included file by php require function

However, in my case I have

for index.php => url[ index.php?var=item]
    <?php
    if(isset($_GET['var'])) {
    $var=$_GET['var'];
    }
    ?>

    <script>
    $(document).ready(function(){
       $("#ok").load("included.php");
    });
    </script>

    <div id='ok'>

    </div>
 in included.php [which will be loaded in index.php by javascript load function]
 <?php
 echo $var;
 ?>

The error was the undefined var in included.php file.How Can I echo this variable with a combination of php and javascript ?

Answer:1

If you want to pass these variables on to the included file you could go with

   $("#ok").load("included.php?<?php echo $urlString; ?>");

The URL string can be generated with this function

function GenGetVars(){
    $Base = NULL;
    foreach($_GET as $key => $variable){
        $Base .= '&'.$key.'='.$variable;
    }
    return(rtrim($Base, '&'));
}

Another option would be :

$( "#ok" ).load( "included.php", { "choices[]": [ "Jon", "Susan" ] } );

Based upon the first example:

index.php:

<?php
function GenGetVars(){
    $Base = NULL;
    foreach($_GET as $key => $variable){
        $Base .= '&'.$key.'='.$variable;
    }
    return(rtrim($Base, '&'));
}

if(isset($_GET['var']) === true) {
    $var=$_GET['var'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Test</title>
    <script type="text/javascript">
    $(document).ready(function(){
       $("#ok").load("included.php?<?php echo GenGetVars(); ?>");
    });
    </script>
</head>
<body>
    <div id='ok'>
    </div>
</body>
</html>

included.php

 <?php
 echo print_r($_GET, true);
 ?>
Answer:2

I want JQuery function to return me the value inside the 'data-tabconfig' <li class="tab-add" data-tabconfig="#{layoutBean.maxTabs}"> I can easily get it if I call onclick function. $(this)....

I want JQuery function to return me the value inside the 'data-tabconfig' <li class="tab-add" data-tabconfig="#{layoutBean.maxTabs}"> I can easily get it if I call onclick function. $(this)....

  1. find data value from percentile
  2. find data value jquery
  3. find data value
  4. find data value matlab
  5. r find value in dataframe
  6. find value in dataframe
  7. find value data r
  8. find value data type
  9. find data attribute value jquery
  10. find data-id value in jquery
  11. find percentile data value calculator
  12. find the data value that corresponds to each percentile
  13. javascript find data value
  14. find minimum data value
  15. find data set value
  16. how to find data value in statistics
  17. find element with data value jquery
  18. how to find data value with z score
  19. find max value data
  20. javascript find data attribute value

I am using extjs 5 on web app using sencha CMD layout (mvvm) and would like to bind a store (for labels) to filter list in my view grid the viewModel store definition is: stores: { labelContacts:...

I am using extjs 5 on web app using sencha CMD layout (mvvm) and would like to bind a store (for labels) to filter list in my view grid the viewModel store definition is: stores: { labelContacts:...

I am trying to mount/unmout a Pixi stage with React (I don't want to use react-pixi yet) I have an error when I re-mount the component: Uncaught Error: Resource with name "cupCake.png" already ...

I am trying to mount/unmout a Pixi stage with React (I don't want to use react-pixi yet) I have an error when I re-mount the component: Uncaught Error: Resource with name "cupCake.png" already ...

I want to understand the best way to improve the performance of jQuery code. Actually, I know how to cache the jQuery selectors to not touch the DOM multiple times as follow: The worst way $('....

I want to understand the best way to improve the performance of jQuery code. Actually, I know how to cache the jQuery selectors to not touch the DOM multiple times as follow: The worst way $('....