Ajax call to delete and update a list not working

I am making an Ajax call to the server to remove a post from li

. The uninstall works fine, but I need to manually exit the list page and when I return, the list will be updated. What I am trying to achieve is that when the button that removes the item refreshes the list as well. I added the following code, but I am not updating :(.

function deleteThisPost() {

    //alert($('#myPostIDStorage').val())
    $.ajax({
        type: 'GET',
        data: 'myPostIDValue=' + $('#myPostIDStorage').val(),
        url: 'http://wander-app.org/deletePosts.php',
        timeout: 5000,
        success: function (data) {
            alert('Post Deleted!');
        },

        error: function () {
            alert('Error Deleting Post');
        }

    });


    return false;
    $('#myPost').listview("refresh");
};

      

+1


source to share


1 answer


Your ajax call works great as you can see there . You should notice that if you return anything from the function, it will no longer be executed. The code you provided below $( '#myPost' ).listview( "refresh" );

will never be verified.

What you probably want to do is

function deleteThisPost() {

    //alert($('#myPostIDStorage').val())
    $.ajax({
        type: 'GET',
        data: 'myPostIDValue=' + $('#myPostIDStorage').val(),
        url: 'http://wander-app.org/deletePosts.php',
        timeout: 5000,
        success: function (data) {


            alert('Post Deleted!');
        },

        error: function () {

            alert('Error Deleting Post');

        }

    });

    $('#myPost').listview("refresh");

    return false;
};

      



As per your question, if you want a dialog with a cancel and confirm button you can do

if(confirm('Do you want to delete?') == true) {
   alert('Deleted');
}

      

+2


source







All Articles