-1

I am trying to pass a product Id from my products.php page to my productType.php using ajax.

products.php

<?php
$test = $_GET['id'];
echo $test;
?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="" src="action.js"></script>

productType.php

<?php
$id = $_GET['id'];
echo $id;
?>

action.js

$.ajax({
  url: "products.php",
  success: function(data){ 
    $.ajax({
      url: "productsType.php?id="+data,
      success: function(data){ 
        alert(data);
      }
    });
  }
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
tomtom94
  • 67
  • 1
  • 9
  • 1
    **For a kind attention to all of you**. Mr TomTom94 is not trying at all. He asked similar question 2 hours before. http://stackoverflow.com/questions/35058794/how-to-get-data-from-one-php-page-using-ajax-and-pass-it-to-another-php-page-usi. And, he asked 6 questions overall in SO and didn't accepted any answer. – Nana Partykar Jan 28 '16 at 12:19
  • Both, products and productTypes could be retrieved in simple API call. What is the purpose of using nested API calls ? – Rayon Jan 28 '16 at 12:19
  • 1
    @NanaPartykar then it is a dupe to close it. – Jai Jan 28 '16 at 12:20

3 Answers3

0

You need to convert it into variable:

$.ajax({
  url: "products.php",
  success: function(data){ 
    $.ajax({
      url: "productsType.php?id=" + data,
      //------------------------^^^^^^^^^
    });
  }
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

You need to concatenate:

url: "productsType.php?id="+data,

or you can use data:{} option of ajax:

url: "productsType.php",
data:{id:data}
Jai
  • 74,255
  • 12
  • 74
  • 103
0

Use following code with async:false

$.ajax({
  url: "products.php",
  async:false,
  success: function(data){ 
    $.ajax({
     async:false,
      url: "productsType.php?id=" + data,
    });
  }
});