0

如果数据库中可用,我会尝试打印 First_name 列表。我使用 wordpress 和 jquery ajax。

这是我的jQuery代码。

    $("#searchbox").keyup(function(){
        //function ajaxSubmit(){

        //var newCustomerForm = jQuery(this).serialize();
        //var emp_nameForm = $('#searchbox').val(); 
        //post_id = jQuery(this).attr("#searchbox");
            post_id=this.value;
            //alert(post_id);
        jQuery.ajax({
        type:"POST",
        url: "/wp-admin/admin-ajax.php",
        data: { action: 'my_custom_handler', emp_name: post_id},
        success:function(response) {
                if(response.type == "success") {
                   jQuery("#search_result").html(data);
                }
                else {
                   alert("Your vote could not be added");
                }
        }
        });

    //return false;
    //}
});

这是我的html代码。

div class="hidesearch" id="search" style="width:"400px;">
                            <input type="text"  id="searchbox"  name="user_name" value=""/>

                    </div>

PHP 代码

function my_custom_handler() {
    global $wpdb;
    $name=$_POST['emp_name'];
    $employee=$wpdb->get_results("SELECT `First_Name` FROM wp_skilllist WHERE First_name LIKE $name% ");

    foreach($employee as $key=> $value){

     echo '<ul>';
     echo '<li>'.$value->First_Name;'</li>';
     echo '</ul>';
  //   echo $value->post_content;
  // echo 'Sasi is  a t est';
   }

    wp_reset_query();
    die();
} // end theme_custom_handler
add_action( 'wp_ajax_my_custom_handler', 'my_custom_handler' );
add_action( 'wp_ajax_nopriv_my_custom_handler', 'my_custom_handler' );

我无法使它工作,有人可以帮助我更正我的代码。

在搜索框中键入名称时,如果它们可用,我想在列表中显示它们。然后用户可以选择一个名称。

实际上成功了:我想打印上面的结果。我试图在 my_custom_handler 上打印文本,但没有打印出来。

4

0 回答 0