i trying use ajax in wordpress.
i don't ajax response. if have done mistake on code, please let me know.
here jquery code
// ajax submitting name $("#sendemp").submit(function(e) { e.preventdefault(); var submit_val = $("#searchbox").val(); alert('submitval ' + submit_val); $.ajax( { type : "post", url : "./wp-admin/admin-ajax.php", data : { action : 'deatils_search', user_name : submit_val }, success : function(data) { alert('hhh'); $('#accordion3').html(data); // $( "#searchbox" ).autocomplete({ // source: data // }); } }); });
here php code
function deatils_search() { $name=$_post['user_name'];//retrive data post array on form submitting $jason =$name; echo json_encode($jason) ; //echo '</div>'; //wp_reset_query(); die(); } // end theme_custom_handler add_action( 'wp_ajax_deatils_search', 'deatils_search' ); add_action( 'wp_ajax_nopriv_deatils_search', 'deatils_search');
i tried print alert('hhh'); on success message in ajax call. doesn't print anything. have done mistake?
please check bellow network tab on chrome
don't use $
jquery shortcut within wordpress javascript. wordpress set run jquery in noconflict mode. replace $
jquery
.
Comments
Post a Comment