zoukankan      html  css  js  c++  java
  • HTML5+ MUI实现ajax的一个demo

    index.html

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <script src="js/mui.min.js"></script>
        <link href="css/mui.min.css" rel="stylesheet"/>
        <script type="text/javascript" charset="utf-8">
              mui.init();
              
              function postdata(){
                  
                  document.getElementById("result").value = "ajax请求发送中……";
                  var input_name = document.getElementById("namevalue").value;
    //          alert(input_name);
                  mui.ajax({
                              url : 'http://127.0.0.1:8080/_ajax/ServerJson.php',
                              type : 'post',
                              headers: {
                                'Content-Type': 'application/json'
                            },
                              data : { name : input_name }, 
                              timeout : 10000,
                              success : function(data){
    //                              console.log(data);
                                  var result = eval('('+ data +')');    //js原生方法解析json字符串为json对象
                                  document.getElementById("result").value = result.name;
                              },
                              error : function(xhr,type,errorThrown){
                                  console.log(xhr);
                                  console.log(type);
                                  console.log(errorThrown);
                              }
                });
    
              }
        </script>
    </head>
    <body>
        
        输入:<input type="text" id="namevalue"></input>
        <button id="btn" onclick="postdata()">发送ajax请求</button>
        <br /><br />
        结果:<input type="text" id="result" value="结果"></input>
    </body>
    </html>

    phpjson.php

    <?php
    
        if($_SERVER["CONTENT_TYPE"]=="application/json"){
            $input = file_get_contents('php://input');
            $name = $input;
            echo $name;
        }else{
            echo "Post Data Error";
        }
        
    ?>
  • 相关阅读:
    SystemManage_系统管理
    安装openoffice.org
    Skill_技巧
    squid代理服务器架设与维护
    FreeBSD 添加硬盘并分区操作说明
    常见游戏端口
    /usr was not properly dismounted 解决办法
    自动获取电信/网通等IP列表
    Cacti文档下载(linux/windows Cacti安装、cacti模板、cacti插件)
    实现基于DNS的负载均衡
  • 原文地址:https://www.cnblogs.com/skysowe/p/6537634.html
Copyright © 2011-2022 走看看