javascript - Can't get json from php -


i beginner in php , wordpress. try make simple plugin can show 3 latest post , show them in page. @ first want array has been encoded in json, , work with js. somewhere in code have mistake or maybe don't understand important. there code return nothing. if delete datatype in ajax, return whole code. advises appreciated. js , php in 1 file.

   <button onclick='myajax()'>button</button>  <script type="text/javascript">     function myajax(){         $.ajax({             type: "get",             url: "plug_in.php",             data: {action: "call_this"},             datatype: 'json',             success:function(data){             alert(data);             }         })     }; </script> <? //plugin name: plagin  //description: plugin getting posts , posts    function show_post(){  $args = array(         'numberposts' => 3     );         $post = get_posts($args);         $all_post = array();         foreach ($post $key) {             array_push($all_post, $key->post_author,$key>post_title,$key>post_content,             $key->post_date);             }               echo json_encode($all_post);         };          if($_get['action'] == 'call_this'){                 show_post();         };  ?> 

try code

function show_post(){     $args = array('numberposts' => 3);     $post = get_posts($args);     $all_post = array();     foreach ($post $key) {         array_push($all_post, $key->post_author,$key-`enter code here`>post_title,$key>post_content,         $key->post_date);     }     echo json_encode($all_post); }  if($_get['action'] == 'call_this'){     show_post(); } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -