Wordpress插件/ Ajax调用

时间:2013-11-01 11:45:56

标签: php jquery ajax wordpress

所以这是我的钩子和功能:

add_action('wp_ajax_AjaxAddDev', 'AjaxAddDev');

public function AjaxAddDev() {

    if (isset($_POST['name']) && isset($_POST['desc'])) {
        $name = $_POST['name'];
        $desc = $_POST['desc'];

        return "Name: ".$name." Description:".$desc;
    }

    return "Problem with data";
    die();
}

这是HTML表单和Jquery调用,目的是基本上为数据库中的表添加名称和描述,但我想让它首先返回提交名称和desc。

            jQuery('#add_dev').bind('submit', function() {
                var url = "<?php echo(get_bloginfo('url')); ?>";
                var form = jQuery('#add_dev');
                var data = form.serialize();
                data.action = 'AjaxAddDev'
                jQuery.post(url+'/wp-admin/admin-ajax.php?', data, function(response) {
                    alert(response);           
                });
                return false; 
            });

    <form method="post" action="" id="add_dev">
        Development Name: <input type="text" name="name">
        Description: <input type="text" name="desc">
        <input type="submit" value="Add Development">
    </form>    

有人有任何想法吗?

响应始终为“0”

0 个答案:

没有答案