Reputation: 460
I am trying to send Rest_ID to another page and using the Rest_ID the ajax on other page is used to fetch data from database.Everything working fine but i am not able to use the value of Rest_ID.
JavaScript Document for fecthing restaurants details on page Restaurant.php
$('document').ready(function(){
loadData();
});
var loadData = function(){
$.ajax({
type: "POST",
url: "../rest_fetch.php"
}).done(function(data){
var restaurants = JSON.parse(data);
for(var i in restaurants){
$("#ft_Rest_list").append("<center><a href='restmenu.php?restid="+restaurants[i].Rest_ID+"'><button type='button' class='btn btn-success load-more-btn' style='border-color:#333;border-radius:0;''>View Menu</button></a></center></div></div>")
}
});
}
JavaScript Document for fecthing item details on page menuitem.php using Rest_ID which is passed by restaurant.php button
$('document').ready(function(){
loadData();
});
var loadData = function(){
$.ajax({
type: "POST",
url: "../menuitem_fetch.php",
data:{"Rest_ID": 201600065},
}).done(function(data){
var menuitems = JSON.parse(data);
for(var i in menuitems){
$("#ft_menuitems").append("<div class='col-sm-3'><div class='thumbnail'><img src='admin/admin/"+menuitems[i].menu_img+"' alt='RestImage'style='width:200px;height:200px;'><h5><strong>"+menuitems[i].Item_Name+"</strong></h5><a href='checkout.php?itemid="+menuitems[i].Item_No+"'><button type='button' class='btn btn-success buy-btn' style='border-color:#333;background-color:transparent;border-radius:0;color:#333;''>BUY</button></a></div></div>")
}
});
}
I need help in getting the value of Rest_ID which is send by restaurant.php page and use by ajax function of menuitem.php page
Upvotes: 1
Views: 157
Reputation: 803
Try to use query parameter when you redirect from one page to another. Let say that when you click some item on restaurant.php you will redirect to
menuitem.php?Rest_ID=ID
so after on menuitem.php you can get Rest_ID by:
var loc = location.search;
loc = loc.split('=')
var Rest_ID = loc[1]
and put it to your request:
$.ajax({
type: "POST",
url: "../menuitem_fetch.php",
data:{"Rest_ID": Rest_ID},
})
Upvotes: 1