Ajax调用删除和刷新不工作列表 [英] Ajax call to delete and refresh list not working

查看:106
本文介绍了Ajax调用删除和刷新不工作列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行一个Ajax调用服务器从里删除帖子。删除工作正常,但我需要从列表页手动走出去,当我回来就行更新。我所努力实现的目标,是当按钮删除项目,也刷新列表。我增加了以下code,但没有刷新:(。

 函数deleteThisPost(){

    //警报($('#myPostIDStorage)。VAL())
    $阿贾克斯({
        键入:GET,
        数据:myPostIDValue ='+ $('#myPostIDStorage)VAL()
        网址:http://wander-app.org/deletePosts.php,
        超时:5000,
        成功:功能(数据){
            警报(后删除!');
        },

        错误:函数(){
            警报('错误删除邮报);
        }

    });


    返回false;
    $('#myPost)的列表视图(刷新)。
};
 

解决方案

您Ajax调用工作正常,你可以看到。你应该采取的通知,如果你从一个函数返回任何东西就不再执行。你下面 $提供的code('#myPost').listview(刷新); 将永不检查。

您可能想要做的是

 函数deleteThisPost(){

    //警报($('#myPostIDStorage)。VAL())
    $阿贾克斯({
        键入:GET,
        数据:myPostIDValue ='+ $('#myPostIDStorage)VAL()
        网址:http://wander-app.org/deletePosts.php,
        超时:5000,
        成功:功能(数据){


            警报(后删除!');
        },

        错误:函数(){

            警报('错误删除邮报);

        }

    });

    $('#myPost)的列表视图(刷新)。

    返回false;
};
 

根据你的问题,如果你想与取消和确认按钮,你可以做一个对话框

 如果(确认(你要删除吗?')==真){
   警报('删除');
}
 

I am implementing an Ajax call to the server to delete a post from a li. The delete is working fine, but I need to manually get out from the list page and when I get back the list is updated. What I am trying to achieve, is that when the button that deletes the item, also refreshes the list. I added the following code but is not refreshing :(.

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");
};

解决方案

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

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;
};

According to your question if you want a dialog box with cancel and confirm button you can do

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

这篇关于Ajax调用删除和刷新不工作列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆