-3

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'];
0

2 Answers 2

1

Pass an object to data:

data: {
    camp: camp_id
}
4
  • Thanks but still doesn't work. What all could be the issue ? Commented Apr 30, 2013 at 21:14
  • @AshishAgrawal: What does $_POST look like? Commented Apr 30, 2013 at 21:14
  • could it be the success function. Is there anything that needs to be added in it ? Commented Apr 30, 2013 at 21:17
  • $_POST: give me nothing. Not even null Commented Apr 30, 2013 at 21:17
1

You may not be declaring/setting camp correctly, it should be something like the below:

var camp = "camp=" + camp_id;
1
  • even that doesnt work. So this php script takes in a value and the result is passed a json object to highcharts. this charts.js file is used in making those charts. When I add my code (the one above) my charts dont get rendered at all. Commented Apr 30, 2013 at 21:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.