my database update with jQuery Ajax it isnt´t working

my database update with jQuery Ajax it isnt´t working

I have a link "Read more", when I click in it, I want to update my news table using php but also jQuery Ajax:

  1. echo '<p>'.$readNewsResult['content'].'<a class="test" href="#fancybox'.$readNewsResult['id_news'].'">Read More</a></p>';

When I click in this link Im getting: "update&update=311", 311 is id of my clicked news, so it is working fine.

But then my php its not working, and it seems that I never enter in my switch condition.

Do you see where might be my error?

This is my jQuery: 






  1. $(function(){
  2.    var read = $('.news');
  3.    read.on('click','.test',function(){
  4.        var updateid = $(this).attr("id");
  5.   var updatedata = "action=update&update="+updateid;
  6.   alert(updatedata);
  7.   $.ajax({
  8. type: "POST",
  9. url: "index.php",
  10. data: updatedata,
  11. beforesend: '',
  12. error: '',
  13. success: function(updateR)
  14. {
  15. alert(updateR);
  16. }   
  17.   });
  18.    });
  19. });
And then, my php
    
  1. $action = $_POST['action'];
  2. switch($action)
  3. {
  4. case 'update':
  5. $id = $_POST['update'];
  6. $updateViews = $pdo->prepare("UPDATE news SET views=:views WHERE id=:id"); 
  7. $updateViews ->bindValue(':views', '1');
  8. $updateViews ->bindValue(':id', $id); 
  9. $updateViews ->execute();
  10. break;
  11.  }