Ben Aerens Ben Aerens - 24 days ago 6
Ajax Question

Pass javascript var to ajax load

Soo I do an ajax load to load a php file in my website. however I need to pass the variable "needednumber" to this php file. How would I do this? And how would I open it in the php file?

<script>
var arr = <?php echo json_encode($arr) ?>;

function deletefunction(pass)
{

var needednumber = arr[pass];

//$description = $_POST['needednumber'];
$('#ajax').load('<?php echo get_template_directory_uri(); ?>/deletefavorite.php?choices=<?php echo $description; ?>');

}



Answer Source

I got it working. I did it with the following:

$.ajax({
                           type: "GET",
                           url: "<?php echo get_template_directory_uri(); ?>/deletefavorite.php",
                           data: {choices: pass},
                           success: function(result){
                             $('#ajax').html(result);
                           }
                         });

                }