send back undefined in ajax
-
hi
in this ajax , returns the “undefined” in alert …
it’s my code :php func :
<?php function myfunc(){ $arr = array( 'var' => 'hello', ); echo json_encode($arr); } add_action('wp_ajax_myfunc', 'myfunc'); add_action('wp_ajax_nopriv_myfunc', 'myfunc'); ?>
and jq :
<script type="text/javascript"> $(function(){ $.ajax({ type: 'post', url: "<?php echo admin_url("admin-ajax.php"); ?>", dataType: 'json', data: { action : 'myfunc', }, success: function(data) { alert(data.var); } }); }); </script>
and also i tried ” alert(data); ” but returns the 0
- The topic ‘send back undefined in ajax’ is closed to new replies.