First. a consideration. of that:
<?php
$album=$_GET['album'];
$id=$_GET['ntf'];
?>
It should be at least that:
$album = ( isset( $_GET['album'] ) ? $_GET['album'] : 0 );
$id = ( isset( $_GET['ntf'] ) ? $_GET['ntf'] : 0 );
Now, regarding your problem, AJAX is a technique to perform asynchronous requests to a resource located from a particular URI.
From what you can understand from your example, what do you expect would happen if the requested page were the same page you are ordering? So:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='http://code.jquery.com/jquery-compat-git.js'></script>
<?php
$album = ( isset( $_GET['album'] ) ? $_GET['album'] : 0 );
$id = ( isset( $_GET['ntf'] ) ? $_GET['ntf'] : 0 );
?>
<script type="text/javascript">
$( function() {
$.ajax({
type: "GET",
url: "test.php",
data: { album: <?php echo $album; ?>, id: <?php echo $id; ?> },
}).done( function( data ) {
$( "#result" ).html( data );
});
});
</script>
</head>
<body>
<div id="result"> Carregando <img src="css/images/gif.gif" width="16" height="16" alt="Loading..." /></div>
</body>
</html>
Whether it’s extra credit or just out of curiosity you’ll go dozens of requests in your browser’s Network/Network tab or a separate extension if you don’t have anything native (Firebug).
What you should do is separate PHP into one/URI file and JS into another. For example:
index php.
$album = ( isset( $_GET['album'] ) ? $_GET['album'] : 0 );
$id = ( isset( $_GET['ntf'] ) ? $_GET['ntf'] : 0 );
echo json_encode( array( 'album' => $album, 'id' => $id ) );
index.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='http://code.jquery.com/jquery-compat-git.js'></script>
<script type="text/javascript">
$( function() {
$.ajax({
type: "GET",
url: "index.php",
dataType: 'json',
data: { album: 10, ntf: 20 },
}).done( function( data ) {
$( "#result" ).html( 'Album: ' + data.album + '. ID: ' + data.id );
});
});
</script>
</head>
<body>
<div id="result"> Carregando <img src="css/images/gif.gif" width="16" height="16" alt="Loading..." /></div>
</body>
</html>
So, when the Request is successfully made the content of the DIV will be current to, in this example, Album: 10 ID: 20
Apart from missing
;
after both of themecho
no mistakes. Must be<?php echo $album; ?>
. I have doubts: This code is on the same page? Can you explain better what the role of AJAX is? how does Ajax run? If AJAX runs when the page loads it would be better to have only PHP without AJAX...– Sergio
Thank you for noticing that ; was missing. Yes the code is on the same page ,what the ajax is doing there and when the page takes photos.php has loaded the delete what is in the div and displays the results that were loaded from the sticky photos.php ,so I have to pass parameters and I can’t send them
– Thepeter