Mohamad Alasly
Mohamad Alasly

Reputation: 340

the click function is removing all changes

i have a Click function , inside it ajax post method, this method is getting info from database after i click the button the info show up for 1 second and then they vanish . this is the code

$('.ViewVisitorMsg').click(function() {
    var requestsID = $(this).attr('data-id');

    $.ajax({
        type: 'post',
        url: baseURL + "admin/Messenger/get_messages_to_admin",
        data: {
            request_id:requestsID
        },
        dataType: 'json',
        success: function(data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].sender == 1) {
                    chatBox.append("<li  class= 'clearfix'><div class='message-data align-right'></div><div class='message other-message float-right'>" + data[i].message + "</div></li>");
                } else {
                    chatBox.append("<li><div class='message-data'><span class='message-data-name'> Vincent</span></div><div class='message my-message'>" + data[i].message + "</div></li>");
                }
            }
        }
    });
});

i tried to put manually one ID and it works. it's like when the click function finish , it resets all variables

EDIT: it's link not a form

Upvotes: 0

Views: 60

Answers (1)

Unmitigated
Unmitigated

Reputation: 89374

You are probably clicking on a button inside a form which is interpreted as a submit button (<button type="submit">), which will submit the form and refresh the page. Change the button to <button type="button"> to prevent it from submitting the form.

Upvotes: 2

Related Questions