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>";
    ?>
    
    
  • 相关阅读:
    shell编程:字符串处理方式
    shell编程:变量替换
    export的用法
    docker stack利用secrets启动wordpress
    docker swarm创建swarm集群
    docker x509: certificate has expired or is not yet valid
    docker-compose的scale的用法
    字符串函数-unquote()函数
    Sass-@each
    Sass-@while
  • 原文地址:https://www.cnblogs.com/timelesszhuang/p/3679903.html
Copyright © 2011-2022 走看看