Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The plugin I am working on has a table in the admin area with a single entry corresponding to single row. The admin has an option to perform certain actions on the table contents one of them being edit. All works well and the js script is as follows -

jQuery(document).ready(function($){

$(".edit").click(function(){

    var first_class = $(this).attr('class').split(" ")[0];
    var message = "message"+first_class;
    var content = jQuery("#"+message).text();
    var $dialog = $("<div></div>").html("<textarea style='width:99%; height:90%' class='popup-content'>"+content+"</textarea>").dialog({
        height: 400,
        width: 400,
        title: 'My Data',
        modal: true,
        autoOpen: false,
        dialogClass: 'wp-dialog',
        buttons: {
            "Save": function(){
                $("#"+message).html($(".popup-content").val());
                $.ajax({
                    type: "post",
                    url: script_data.admin_ajax,
                    data: {
                        action: "feedmng_update",
                        feed_id: first_class,
                        feed_msg: $(".popup-content").val()
                    },
                    error: function(xhr, status, error) {
                        console.log(xhr, error, status);
                    },
                    success: function(){
                        $dialog.dialog("close");
                    }
                });
            }
        }
    });
    $dialog.dialog("open");
    });
});

As can be seen, on clicking Save button, Ajax call is made to update the databse, which works well too.

Now I want to display a message that the database has been updated, but I cant seem to do it right. Here is the php code -

function feedmng_update(){

    global $wpdb;
    //$tablename = $wpdb->prefix. "feedmanager";
    $feedid = $_REQUEST["feed_id"];
    $feedmsg = $_REQUEST["feed_msg"];
    $wpdb->update( 'wp_feedmanager', array( 'message' => $feedmsg ), array( 'id' => $feedid ) );
    add_action( 'admin_notices', array( &$this, 'feedmng_edit_notif' ) );
}

function feedmng_edit_notif(){

    ?>
    <div class="updated">
        <p><?php echo "Message succesfully edited"; ?></p>
    </div>
    <?php
}

Action hook for ajax -

add_action( 'wp_ajax_feedmng_update', array( &$this, 'feedmng_update' ) );

Is there a way to get it working ?

share|improve this question
    
Are you using the ajax action hooks to call the function feedmng_update? I dont see it here in the codes? –  Maruti Mohanty Nov 15 '13 at 6:26
    
Yes I am, did not post it though ! –  Navin Nov 15 '13 at 7:25
    
It works (Ajax part involving DB update) all well. The only prob is with the custom message. –  Navin Nov 15 '13 at 7:39
    
ok so you have the ajax hook name and callback function name same –  Maruti Mohanty Nov 15 '13 at 8:19
    
Included that too above to avoid confusion –  Navin Nov 15 '13 at 8:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.