<h2>添加特色</h2>
<label for="feature">特色：</label>
<input id="feature" type="text">
<input type="submit" id="submit" class="button">
<script>
    var admin_url = '{{ admin_url }}';
    (function ($) {
        $(document).ready(function () {
            $('#submit').click(function () {
                var name = $('#feature').val();
                if (name.trim() != '') {
                    $.ajax({
                        type: 'POST',
                        url: '{{ url }}/wp-admin/admin-ajax.php/',
                        data: 'action=add_feature&name=' + name,
                        success: function (data) {
                            switch (data.code) {
                                case 2000:
                                    window.location.href = admin_url + 'admin.php?page=feature_list';
                                    break;
                                case 2001:
                                    alert('不能重复添加特色');
                                    break;
                                default:
                                    break;
                            }
                        }
                    });
                } else {
                    alert('请输入特色');
                }
            });
        });
    })(jQuery);
</script>