2
I want to load a page inside a div via load passing a variable that will define the contents of the page to load.
My code:
index php.
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
</head>
<script>
$(document).ready(function(){
$('.carrega').click(function(){
$('#aqui').load('pagina.php?variavel='+$('.carrega').val());
});
});
</script>
<?php
$arr = array('azul', 'branco', 'cinza');
for ($i = 0; $i < count($arr); $i++) {
$temp=$arr[$i];
echo "<button class='carrega' value='$temp'>$temp</button>";
}
?>
<div id="aqui"></div>
</html>
php page.
<?php
$variavel=$_GET['variavel'];
echo $variavel;
?>
The page loads correctly, but only the first variable is passed through the URL. I don’t know what I’m doing wrong, could someone give me a hand?
Thank you very much!!!
– Amanda Lima