This question already has an answer here:
I have two file one charts.js and the other getdata.php. The charts.js file has a variable campaignId (this is an number) which I need to pass to my getdata.php file where I want to put campaignId in a MySQL query. The issue is that the value is not getting passed to the php file. how do I resolve this issue. Thanks
I am running all my code locally. Using MAMP. All my code files are in one folder and the path is given to MAMP.
In the charts.js file this is what I am writing.
function category(camp_id){
camp = camp_id;
$.ajax({
type: "POST",
url: "http://localhost:8888/getdata8.php",
data: camp,
error:function() {
alert("sorry")
},
success: function(result) {
alert(result);
}
});
}
In my PhP I am doing:
$id= $_POST['camp'];
</div>
Pass an object to data
:
data: {
camp: camp_id
}
You may not be declaring/setting camp correctly, it should be something like the below:
var camp = "camp=" + camp_id;