How to pass several PHP variables using a HTML link and do not refresh the page? -


i have code:

$page = $_get['page']; 

then want call page inside index.php?page=

if($page == "view_data")  {   include "view_data.php"; } else if($page == "edit_data") {   include "edit_data.php?id="; } else if($page == "delete_data") {   include "delete_data.php?id="; } else {   echo "cannot found page"; } 

i make link generate if function above.

<a href="index.php?page=edit_data&id=<?= $row['id_data'] ?>">edit</a> <a href="index.php?page=delete_data&id=<?= $row['id_data'] ?>">delete</a> 

my problem how pass edit data or delete data if have use 2 variables in link edit , delete data can execute 1 page?

i suggest using ajax in client-side:

function doaction(page,id) {   var xmlhttp=new xmlhttprequest();    xmlhttp.onreadystatechange=function()   {     if (xmlhttp.readystate==4 && xmlhttp.status==200)       {         var response=xmlhttp.responsetext;         alert(response);//if want notify user job done       }     }     xmlhttp.open("get","index.php?page="+page+"&id="+id,true);     xmlhttp.send();   } } 

and html using onclick attribute

<button onclick="<?php echo "doaction(\"edit_data\",".$row['id_data'].")"; ?>">edit</button> <button onclick="<?php echo "doaction(\"delete_data\",".$row['id_data'].")"; ?>">data</button> 

the rest of php code can remain unchanged


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -