Javascript 通过ajax在特定时间后加载内容

Javascript 通过ajax在特定时间后加载内容,javascript,jquery,Javascript,Jquery,我正在尝试从数据库中获取数据,而无需重新加载。所以我做了这个 完成后,这就是单击的ajax部分 function ed_action(p_authority_id, ed_value) { $.ajax({ method: "POST", url: "inc/ed_action.php", data: 'p_authority_id='+ encodeURIComponent(p_authority_id)

我正在尝试从数据库中获取数据,而无需重新加载。所以我做了这个

完成后,这就是单击的ajax部分

function ed_action(p_authority_id, ed_value) { $.ajax({ method: "POST", url: "inc/ed_action.php", data: 'p_authority_id='+ encodeURIComponent(p_authority_id) + '&ed_value='+ encodeURIComponent(ed_value), success: function(data) { if(data){ $("#show").html(data); } } }); } 功能ed_操作(p_权限id、ed_值){ $.ajax({ 方法:“张贴”, url:“inc/ed_action.php”, 数据:'p_authority_id='+encodeURIComponent(p_authority_id)+'&ed_value='+encodeURIComponent(ed_value), 成功:功能(数据){ 如果(数据){ $(“#show”).html(数据); } } }); } 这是ed_action.php文件

$func = new functions(); if($_SERVER["REQUEST_METHOD"] == "POST"){ $ed_value = $_POST['ed_value']; $p_authority_id = $_POST['p_authority_id']; $user_data = array( 'ed_action' => $ed_value ); $where_cond = array( 'where' => array('p_authority_id' => $p_authority_id), 'cross_check' => 'and', 'return_type' => 'single' ); $table_name = 'p_authrity_user'; $update = $func->update($table_name, $user_data, $where_cond); $ed_action_data = $func->select($table_name, $where_cond); } $func=新函数(); 如果($\服务器[“请求\方法”]=“发布”){ $ed_value=$_POST['ed_value']; $p_authority_id=$_POST['p_authority_id']; $user\u data=数组( “ed_动作”=>$ed_值 ); $where_cond=数组( '其中'=>数组('p_authority_id'=>$p_authority_id), '交叉检查'=>'和', '返回类型'=>'单个' ); $table_name='p_authrity_user'; $update=$func->update($table\u name,$user\u data,$where\u cond); $ed\u action\u data=$func->select($table\u name,$where\u cond); } 我通过单击成功地检索了数据。但现在我想当我点击启用按钮时,它将显示禁用按钮而不重新加载,当点击禁用时,它应该显示启用按钮。那我该怎么办


您能帮我吗?

正如我在评论中提到的:在ajax请求的成功功能中,您只需切换两个按钮的可见性即可

function ed_action(p_authority_id, ed_value) {
    $.ajax({
        method: "POST",
        url: "inc/ed_action.php",
        data: 'p_authority_id='+ encodeURIComponent(p_authority_id) + '&ed_value='+ encodeURIComponent(ed_value),
        success: function(data) {
            if(data){
                $("#show").html(data);
                toggleButtons();
            }
        }
    });
}

function toggleButtons(){
    var enableBtn = $('button.ed_action.ed_action_enable'); // add class ed_action_enable to button so you can get it here
    var disableBtn = $('button.ed_action.ed_action_disable'); // add class ed_action_disable to button so you can get it here

    enableBtn.toggle(); // toggles visibility of element
    disableBtn.toggle(); // toggles visibility of element

    /* shorter code for this:
    $('button.ed_action.ed_action_enable').toggle;
    $('button.ed_action.ed_action_disable').toggle;
    */
}
要想让它发挥作用,你需要

1:将两个按钮输出到html中(禁用btn隐藏)


2:在按钮中再添加一个类,这样您就可以使用jquery轻松地获取它们了

您可以将这两个按钮都放入html中,但禁用按钮是使用css隐藏的。单击enable按钮时,使用javascript/jquery隐藏enable按钮并显示disable按钮。禁用按钮也一样。谢谢你的评论。我试过了,但我能用ajax做到这一点吗?你可以调用一个函数,在ajax的成功回调中隐藏/显示这些元素。怎么做??你能帮我吗?我要做一些工作,如果在一小时内没有人提供答案,我会给你举个例子,直到那时你忘记添加类ed_action_disables抱歉。但同样的事情发生了,如果它仍然“没有显示任何内容”,您可以使用警报进行调试,以找出可能的错误。我现在就到此为止,祝大家愉快。我怀疑ajax成功没有被触发,或者成功函数中没有收到数据,干杯