Jits Jits - 3 months ago 12
PHP Question

Use client side values in 2nd php file via Ajax

I have three php files.

filter.php - to send Ajax request and get response
insert.php - to store Ajax response
getResponse.php - to use stored Ajax response.


Primary purpose of doing all these thing is to use client side values using PHP code because server & client can't exchange variable values each other.

Expected: Response should be stored in php variable in getResponse.php.

I got array response in insert.php but how can i use in getResponse.php?

For e.g.

---------- filter.php ----------

<script>
$.ajax({
type: "POST",
url: "filter.php",
data: { name: tp, country:"test"},


success:function(response) {
var res = response;
$.ajax({
type: "POST",
url: "insert.php",
data: { res: res },

success:function(data){
alert(data);
}
});
});
<script>


-------- insert.php ----------

if ($_POST) {

if ($_POST['id1'] !== "") {

echo $_POST['id1'];

}

}


-------- getResponse.php ----------

Code to get array response from Ajax via filter.php and insert.php ?

Need to store these array value and do manipulation accordingly.

Thanks for your help in advance!

Answer

Here is the answer:

<script>

$.ajax({
  type: "POST",
  url: "filter.php",
  data: { name: tp, country:"test"},

  success:function(response) {
   var res = response;
   $.ajax({
    type: "POST",
    url: "getResponse.php",
    data: { res: res },
     success:function(data){
      alert(data);
     }
  });
});

</script>
Comments