黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
var params = $("form").serialize();
$.ajax({
                    type:"POST",
                    url:"www.xxxxxx.com",
                    data:params,
                    dataType: "json",
                    success:function(data){
                            var backdata = "您提交的姓名为:" + data.name;
for(var i = 0; i<data.posts.length;i++)
{
alert(data.posts[i].id + data.posts[i].title);
break;
}


                            },
                    error:function(XMLHttpRequest, textStatus){                       
                        if(XMLHttpRequest.status==500){
                            var result = eval("("+XMLHttpRequest.responseText+")");
                            alert(result.exception.message);
                          }
                   }
});

wordpress获取文章

<?php
global $wpdb;

if(!$_POST)
{ exit; }

$cat = htmlspecialchars(trim($_POST["cat"]));
$limit = htmlspecialchars(trim($_POST["limit"]));
$count = htmlspecialchars(trim($_POST["count"]));


$args = array('numberposts' => $count, 'offset'=> $limit, 'category' => get_category_by_slug($cat)->term_id,'post_status' => 'publish');   
$posts = get_posts($args);
$ary = array('result'=>count($posts),'posts'=>array());
foreach( $posts as $post ) {
    array_push($ary["posts"],array('id'=>$post->ID,'title'=>$post->post_title));
}
echo json_encode($ary);
exit;
?>
View Code

 

 

posted on 2011-10-06 16:23  黄聪  阅读(5419)  评论(0编辑  收藏  举报