ajax calling in backend of wordpress

First include your ajax page.

require_once(“ajax.php”);

In this page add code as below: using wp_ajax hook:

<?php
function select_products() {
$cat=$_REQUEST[“data”][“articletitle”];
$args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ =>-1, ‘product_cat’ => $cat, ‘orderby’ => ‘name’ );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :  while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<option name=”pdts” class=”pdts2″ value=”<?php the_title(); ?>”><?php the_title(); ?></option>
<?php
endwhile;
endif;
}
add_action( ‘wp_ajax_select_products’, ‘select_products’ );

?>

Call the ajax function:

function update_products(val) {
$.post(
ajaxurl,
{
“action”: “select_products”,
“data”:   { articletitle: val }
},
function(response){
jQuery(“.pdts2”).remove();
jQuery(“#products_name”).append(response);
}
);

}