0

我正在为我的WordPress站点创建一个插件,该插件在更改了选择框时,然后通过调用WordPress数据库来更改以下选择选项。

对于我的生活,我无法让它发挥作用。

这是wordpress编码:

function ubl_ug_load_ajax(){
    if(isset($_GET['page']) && $_GET['page'] == 'ubl-unlimited-galleries-image'){

        wp_enqueue_script('ubl-ajax', plugin_dir_url(__FILE__) . 'js/ubl-ajax.js', array('jquery'));

    } else {
        return;
    }
}

add_action('admin_enqueue_scripts','ubl_ug_load_ajax');

function ubl_uimages_page(){

global $wpdb;

    // GET CATEGORIES
    $getcatsforimages = $wpdb->get_results("SELECT id, galleryname FROM ubl_galleries");

    if($getcatsforimages){

        // ADD MODE
        if(!isset($_GET['ublmode'])){

            $ublerrors = array();

            $galleryname = '';
            $gallerycats = '';

            if(isset($_POST['issent'])){

                // do something

            }

            $output = '

                <style>
                h1{padding:0px 0px 10px 0px;margin:0px;}
                h3{padding:40px 0px 10px 0px;margin:0px;}
                .wrap{margin:0px;padding:15px;width:50%;}
                .widget .widget-top, .postbox h3, .stuffbox h3{padding:5px 10px; color:#1e1e1e}
                .widget, #widget-list .widget-top, .postbox, #titlediv, #poststuff .postarea, .stuffbox{
                    background-color:white;
                }
                .postbox .inside, .stuffbox .inside{padding:20px;background-color:whiteSmoke;}
                .red{color:red;}
                .green{color:green;}
                .regular-text{margin-bottom:20px;}
                h4{margin:0px;padding:8px 0px 3px 0px;}
                .inside > p{padding:3px;margin:0px;}
                hr{border-color:white;background-color:white;}
                .stuffbox img{max-width:300px;height:auto;}
                </style>

            ';

            $output .= '<div class="wrap">';

            $output .= '<h1>Add New Gallery</h1>';
            $output .= '<form method="post" action="" enctype="multipart/form-data">';
            $output .= '<input name="issent" type="hidden" value="1" />';
            $output .= '<div class="stuffbox"><h3><label>Gallery Details</label></h3><div class="inside">';
            $output .= '<h4>Gallery Name</h4><p>';
            $output .= '<select name="galleryname" class="galleryname">';
            foreach($getcatsforimages as $getc){
            $output .= '<option value="'.$getc->id.'">'.$getc->galleryname.'</option>';
            }
            $output .= '</select>';
            $output .= '<hr>';
            $output .= '<h4>Gallery Categories &amp Slude</h4><p class="gallerycats"></p>';
            $output .= '<p>Please Choose A Category</p>';
            $output .= '</div></div>';
            $output .= '</form>';
            $output .= '</div>';

            echo $output;

        }

    } else { ?>
    <div class="wrap"><h1>Please Create Galleries First</h1></div>
    <?php }

}

这是ajax文件编码:

jQuery(document).ready(function() {

        jQuery(".galleryname").change(function(){

            var ubl_get_results=jQuery(this).val();
            var url = '../wp-content/plugins/ul/ajax.php'

            data = {
                 ajaxid: ubl_get_results,
                };

            jQuery.post(url, data , function (data) {

                //jQuery('.gallerycats').html(response);

                alert(data);

            });

        return false;
        });

});

然后这里是 ajax 也发布的 php 文件:

if(isset($_REQUEST['ajaxid'])){

    echo 'this works';

} else {

    echo 'Could Not Do This';

}
4

0 回答 0