Jump to content

passing multiple data through ajax


krrish

Recommended Posts

I need to pass multiple data through ajax, and also should post back it in another page. but my code is not working,

this is my code:

 

var data = {page_num: page,gender: <?php echo $gender;?>this_year: <?php echo $year;?>};$.ajax({ type: "POST", url: "data.php", data: data, success: function(res) { $("#result").append(res); console.log(res); } });

 

 

POST the values(data.php):

 

echo $page = $_POST['page_num'];echo $gender = $_POST['gender'];echo $fromyear = $_POST['this_year'];
please guys help me. thnx,
Edited by krrish
Link to comment
Share on other sites

check the data, dump it in console.log(). verify the data it is sending to the data.php. unless you are using a php page to generate JS page, <?php echo $gender;?> this wont work. php code block only execute in php context.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...