jQuery ajax call behaving unexpectedly

Hi there,

I have a database driven website, which shows a list of files that have been uploaded by users.

I have a script called controller.php, which generates the HTML:

<?php foreach($uploads as $upload): ?>
<div class="upload">
<p><?php echo $upload['filename'] ?> | 
      <?php echo $upload['size'] ?> | 
      <?php echo $upload['type'] ?>
<form method="post" action="index.php">
<input type="hidden" name="id" value="<?php echo $upload['id'] ?>
<input type="submit" name="download" id="download" value="Download">
<input type="submit" name="delete" id="delete" value="Delete">
<?php endforeach; ?>

When the download button is clicked, the file is downloaded, and then deleted from the server, and the database entry is deleted.

All gravy so far, now I need to update the page, so that the downloaded/deleted item does not show on the page anymore.

So here’s my Jquery:

  $('#download, #delete').click(function(){

All works fine, until I re-load the controller.php script on the click event of ‘#download’, nothing changes.

I guess it could be for one of two reasons. Either a) I am reloading the script before the changes have been made to the database, or b) .load() doesn’t behave this way, and I should be approaching this problem a different angle.

Any assistance would be great.

Many thanks,

This has been solved.

The issue was that I was performing the SQL query on a different script to the one that I was trying to load, so the HTML was being generated by the controller script before the database shenanigans occurred. I could only ever load the same HTML.

I moved the database script to the controller script and works like a charm.


That was awesome. You posted the problem, and then followed up with specifically how you fixed it.

Wish more posters did that, instead of just “oh wait I got it” :slight_smile:

Aww, shucks! :blush:

Actually, I realise now that that post is acomplete a fabrication. I actually ended up doing things slightly differently. I realised I didn’t need to make an ajax call at all, i just hid the div like so:


Then I moved the php script back to index.php. If the user ever reloads the page, it looks seamless, cos the div that’s been deleted is not generated by the php script.

It’s a work-around cos I actually could get the desired effect using the .load() function as I described above, plus I think it’s probably more efficient.