How can I make comments, for example in stackoverflow?

How to make comments, for example, in stackoverflow?

What I mean more specifically, I use php / mysql, as if to add a comment without reloading the page, I know that this is a simple process of using AJAX, but when you post a comment on SO, it also has the ability to delete it right away when I insert comments into my database, the identification number of the car is increasing, so my real question is now

After posting a comment, a comment is posted, added only to the page with some javascript to add content to the page

OR

Does AJAX use this comment you just posted and then display it on the page?

The reason I am wondering is because, since my system uses auto increment ID, then if I made it the first method, which would be faster, to just declare the content that I posted when sending, but this the method would not give me the identifier, which is necessary in order to be able to delete a comment by identification number

Hope that makes sense

UPDATE I posted below what I think now, after reading the other posts here.

+3
source share
6 answers

UPDATE

After reading the answers, here is my main idea, I don’t know how to write javascrpt, but you get the idea of ​​a design flow:

POST comment input to script with AJAX {    
    if commentID is returned{
        Insert comment DIV into page, userID and userPicture are in a user session variable and commentID is returned from ajax post
    }ELSE IF error is returned{
        Insert an error message DIV into page
    }
}

div -
-
- userID
-
- ,

,

POST comment ID and userID to DELETION script with AJAX {    
    if commentID is deleted{
        REMOVE comment DIV from page
    }ELSE IF error is returned{
        Insert an error message DIV into page
    }
}
0

. , ...

... , AJAX, ID .

( : , ... , )

+5

, , AJAX, , , AJAX , , , javascript. , , .

: , AJAX HTML-, , . AJAX.

+2

- jQuery:

function commentSubmit()
{
  $.post('/ajax/comment',{comment:$('#comment').val()},function(d){
    if(d is error) alert(d);
    else $('#allcomments').append(d);
  })
}

d html .

+1

ajax php script, mysql. ajax ( ). delete ajax PHP , script. .

0

If you want to delete a comment, you must contact the server, so you must use ajax. Just send a comment to the server, wait for the comment identifier to return, then format the comment in some HTML, hide the new comment identifier somewhere in the new HTML (possibly in the link to delete the comment) and wala.

0
source

Source: https://habr.com/ru/post/1713701/


All Articles