zoukankan      html  css  js  c++  java
  • jquery ajax(3).post

      .post返回文本数据
    $(function(){ $("#send").click(function(){ $.post("post1.php", { username : $("#username").val() , content : $("#content").val() }, function (data, textStatus){ $("#resText").html(data); // 把返回的数据添加到页面上 } ); }) })
    php文件
    <?php 
        header("Content-Type:text/html; charset=utf-8");
        echo "<div class='comment'><h6>{$_REQUEST['username']}:</h6><p class='para'>{$_REQUEST['content']}</p></div>";
    ?>
    
    
      .post 返回xml数据

    $(function(){ $("#send").click(function(){ $.post("post2.php", { username : $("#username").val() , content : $("#content").val() }, function (data, textStatus){ var username = $(data).find("comment").attr("username"); var content = $(data).find("comment content").text(); var txtHtml = "<div class='comment'><h6>"+username+":</h6><p class='para'>"+content+"</p></div>"; $("#resText").html(txtHtml); // 把返回的数据添加到页面上 },"xml"); }) })

    php 文件
    <?php 
        header("Content-Type:text/xml; charset=utf-8");
        echo "<?xml version='1.0' encoding='utf-8'?>".
             "<comments>".
             "<comment username='{$_REQUEST['username'] }' >".
             "<content>{$_REQUEST['content']}</content>".
             "</comment>".
             "</comments>";
    ?>
    
    
    
    
    
    
     
     .post 返回json数据实现
     $(function(){
           $("#send").click(function(){
                $.post("post3.php", { 
                            username :  $("#username").val() , 
                            content :  $("#content").val()  
                        }, function (data, textStatus){
                            var username = data.username;
                            var content = data.content;
                            var txtHtml = "<div class='comment'><h6>"+username+":</h6><p class='para'>"+content+"</p></div>";
                            $("#resText").html(txtHtml); // 把返回的数据添加到页面上
                        },"json");
           })
        })
    php文件
    <?php 
        header("Content-Type:text/html; charset=utf-8");
        echo "{ "username" : "{$_REQUEST['username']}" , "content" : "{$_REQUEST['content']}"}" 
    ?>
    
    
    
    
    .load注意是
    $(function(){ $("#send").click(function(){ $("#resText").load("post1.php",{ username : $("#username").val() , content : $("#content").val() }) }) })
    <?php 
        header("Content-Type:text/html; charset=utf-8");
        echo "<div class='comment'><h6>{$_REQUEST['username']}:</h6><p class='para'>{$_REQUEST['content']}</p></div>";
    ?>
    
    
  • 相关阅读:
    复制带有random指针的单链表
    loadrunner常见问题
    【转】性能测试、负载测试、压力测试的区别
    文件存储结构inode与RAM结构建立联系
    inode表元数据,存储在物理存储体上
    debug宏起作用应用
    linux内核常用函数或宏
    file、inode在应用层和驱动层之间的联系_转
    内核交互--sysfs
    内核交互--procfs
  • 原文地址:https://www.cnblogs.com/timelesszhuang/p/3679903.html
Copyright © 2011-2022 走看看