I would like to pass a php variable onto another php page (category-get-secondary.php) through Ajax. I have the following code:
function getSecondaryCat(val) {
$.ajax({
type: "POST",
url: "category-get-secondary.php",
data: 'primary_cat='+val,
success: function(data){
$("#secondary_cat").html(data);
$("#tertiary_cat").html('<option value="">Select specific category</option>')
}
});
}
On category-get-secondary.php I want to get the value: -
$postPrimaryCat = $_POST['primary_cat'];
$categoryType = $_POST['category-select'];
$postPrimaryCat is transferred. Now I want to transfer the value for $categoryType.
I would like to pass the PHP variable 'category-select'. This is what I tried to transfer the value:
function getSecondaryCat(val,cat_val) {
$.ajax({
type: "POST",
url: "category-get-secondary.php",
data:'primary_cat='+val+'&category-select='+cat_val,
success: function(data){
$("#secondary_cat").html(data);
$("#tertiary_cat").html('<option value="">Select specific category</option>')
}
});
}
and to get the value I'm using
$getCategorySet = $_POST['category-select'];
but the value doesn't seem to be transfereed
Updated with full code:
main-page.php
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
</script>
<script>
function getSecondaryCat(val, catval) {
$.ajax({
type: "POST",
url: "category-get-secondary.php",
data:'primary_cat='+val+'&categoryselect='+catval,
success: function(data){
$("#secondary_cat").html(data);
$("#tertiary_cat").html('<option value="">Select specific category</option>')
}
});
}
function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
</script>
<?php
//Get category set from URL bar
$_POST['categoryselect'] = 'premium';
category-get-secondary.php
<?php
//Insert value to ajax
$postCatType = $_POST['categoryselect'];
$_POST['category_select'] = 'private';category-selecttocategory_select