javascript – Ajax not moving to the next page-ThrowExceptions

Exception or error:

I am displaying images dynamically from the database in a PHP page. I get the ID of the clicked image using JavaScript. when I try to pass the value to the next page in JS using localStorage, it works fine. But when I try AJAX (because I want to send the variable in JSON so I can read it using PHP) it shows the index of the clicked image but it is not redirecting me to the next page?

this is the code:


    require "init.php";

    <script src=""></script>
    <script >

function myFunction(clicked) {
  document.getElementById('test').innerHTML = clicked;
  // this can help the user to store the value locally AND recall it when he needs it from JS
 // localStorage.setItem('index',clicked);
 // window.document.location='./test1.php'

 //using AJAX to pass the variable and read it using PHP in the next page
  var loc={};;
      success: function(res)


<title> Expert System </title>
    <link rel="stylesheet" type="text/css" href="css/style.css">

    <button id="1" onclick="myFunction(">This will show date when clicked.</button>

<p id="test"> </p>

function login(){
    global $con;
    global $counter;
echo "<table border='1' align='center'     >";
    //$email = $mysqli->escape_string('');
    $query="SELECT * FROM users ";
    if ( $result->num_rows == 0 ) // User doesn't exist
        echo "User with that ID doesn't exist!";
    else { // User exists
     $counter = 0;
     $emptyArray = [];

while($row = $result->fetch_assoc()) 
       $emptyArray[$counter]= $row["ID"];
       if($counter == 0)
           echo '<tr>';
       echo '<td><img id=' . $row["ID"]. ' onClick="myFunction(" src="images/' . $row["category"]. '" width="250px"  height= "150px" alt="Avatar" >
       <h3>'.$emptyArray[$counter].'</h3> <p id = "GFG_DOWN" style =  
            "color:green; font-size: 20px; font-weight: bold;"> dfsfds
        </p> </td>';
       if($counter == 3)
            echo "</tr>";
            $counter = 0;



How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *