I’ve been sending ajax for a long time, but this wasn’t: it’s sent only once, and then when I click on the div (.msgdel class) it just reloads the page.

$('.msgdel').click(function () { var id = $(this).attr('id'); var data = "comid=" + id; alert(data); $.ajax({ type: "POST", url: "comdel.php", cache: false, data: data, success: function (html) { $('div#commentsdiv').load("# div#commentsdiv"); } }); return false; }); 

How to fix this line? Without it, everything is in order. How to update a specific div?

 $('div#commentsdiv').load("# div#commentsdiv"); 

    2 answers 2

    Maybe I don’t understand js and jquery in particular, but I don’t understand the construction:

      $('div#commentsdiv').load("# div#commentsdiv"); 

    more precisely what it should do. for the rest:

    1. it is possible that .msgdel is inside the #commentsdiv container then of course the click will get lost it is treated simply instead

       $('.msgdel').click(function(){}); 

      use

       $('body').delegate('.msgdel','click',function(){}); 
    2. Downloading content into the necessary block is carried out in your case like this:

       success: function(html){$('div#commentsdiv').html(html); 
    • Unfortunately, the proposed method of downloading content does not work = ( - glarionenko

    In your example, _POST goes to the file yyy.php. But judging by the structure of the index.php file,

     <? ... [код] ... ... [Include <FORM>]... ... [Include обработчика]... ?> 

    Something turns out to be hellish after you have checked and written data in the database, stick in the redar function with the index and see what happens, you will understand by trial and error. And even easier just experiment on the bare raw!

    You can throw a heading anywhere, even on the Borg website, even on a php file, I screwed the info about this function in response! The main thing you need to understand when working with a header is that it is governed by the HTTP header, and for example ECHO and PRINT, you cannot use it before the header.

    • @Yura Vfhfh, To format the code, select it with the mouse and click on the 101010 editor button. - angry