zoukankan      html  css  js  c++  java
  • 黄聪:jquery对ajax的error内的XMLHttpRequest返回的exception获取里面的信息

    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

  • 相关阅读:
    第十三周课程总结
    第十二周课程总结
    第十一周课程总结
    C语言||作业01
    C语言寒假大作战03
    C语言寒假大作战4
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    第一周作业
  • 原文地址:https://www.cnblogs.com/huangcong/p/2199988.html
Copyright © 2011-2022 走看看