Jump to content
aveeva

Get variable value to another PHP page using AJAX

Recommended Posts

Posted (edited)

 

My index.php,


 
$output .= '
		<div class="col-sm-3 col-lg-4 col-md-3">
			<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
				<audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
					<source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
				</audio>
				<p align="center"><strong> '. $row['voice_name'] .'</strong></p>

				<p style="font-size: 12px;">
				Id				  : '. $row['voice_id'].' <br />
				Name			  : '. $row['voice_name'].' <br />
				Gender		      : '. $row['voice_gender'].' <br />
				Genres 			  : '. $row['voice_genres'].' <br />
				Voice Modulation  : '. $row['voice_voice_modulation'].' <br />
				Languages		  : '. $row['voice_languages'].' <br />
				Jingle Moods	  : '. $row['voice_jingle_moods'].' <br />
				Ivr 			  : '. $row['voice_ivr'].' <br /> </p>
				
				<button type="button" class="btn btn-primary" type="submit" onclick="addCart('. "'".$row["voice_id"]."'".','."'". $row["voice_name"]."'".');" style="padding: 5px 83px 5px 83px;">Add to PlayList </button>

same page ajax :

 

<script>
function addCart(voice_id, voice_name)
	{

		$.ajax({
			type: 'POST',
			url: 'cart.php',
			data: {
				voice_id   : voice_id,
				voice_name : voice_name
			},
			dataType: 'text',
			success: function(data) {
				// alert(data);


			}
		});
	}
$(document).ready(function(){

});
</script>

and get.php

 

<?php 


$voice_id =" ";
$voice_name=" ";
if(isset($_POST['voice_id']) && isset($_POST['voice_name']))
{
    $voice_id = $_POST['voice_id'];
    $voice_name = $_POST['voice_name'];

}

echo "$voice_id, . "&". , $voice_name";


?>

if click button, the value send but the get.php not properly get the value and display on the php page.

 

Edited by aveeva

Share this post


Link to post
Share on other sites

First of all, not really sure what this line is all about.

echo "$voice_id, . "&". , $voice_name";

I see your "alert" test in your jQuery ajax success.  That is good, but do more.  Did you use Chrome's console inspector (or similar other browsers) to ensure the browser client is sending data?  Next, be really simple at the server and just use exit('<pre>'.print_r($_POST).'</pre>'); or var_dump($_POST);.

Share this post


Link to post
Share on other sites
45 minutes ago, aveeva said:

if click button, the value send but the get.php not properly get the value and display on the php page.

That may be because your ajax request is sent to "cart.php"

46 minutes ago, aveeva said:

$.ajax({ type: 'POST',

url: 'cart.php',

data: { voice_id : voice_id, voice_name : voice_name },

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.