0

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

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”

4

0 回答 0