zoukankan      html  css  js  c++  java
  • ajax 整理

    1.load() 点击加载服务器内容

    <a href="">点击</a>
    <div id="contant"></div>
    <script>
    
    	$("a").click(function(){
    		$("#contant").load("00.txt");return false;
    
    	});
    
    </script>
    

    2.POST ajax 传参数插入数据库

                       $.ajax({
    				type: "POST",
    				url: "insert.php",
    				data: {
    					author: $("#author").val(),
    					message: $("#message").val()
    				},
    
    				success: function(msg) {
    					alert("moren:" + msg);
    				}
    			});
    

      

      insert.php

    <?php 
    
    include 'config.php';
    $username=$_POST['site'];
    $password=$_POST['class'];
    echo $username.$username;
    $sql="INSERT INTO pmw_admanage(siteid,classid) values('$username','$password') ";
    $smt=$pdo->prepare($sql);
    if ($smt->execute()) {
    echo "成功";
    }else{
    	echo "不成功";
    }
    
    
     ?>
    

    ajax 整理

    $(".layui-btn").click(function () {
    			$.ajax({
        url:"aa.php",    //请求的url地址
        dataType:"json",   //返回格式为json
        async:true,//请求是否异步,默认为异步,这也是ajax重要特性
        data:{"id":$("h1").text()},    //参数值
        type:"POST",   //请求方式
        beforeSend:function(){
             alert("请求之前 ")
        },
        success:function(msg){
          $(".layui-container").html(msg)
        },
        complete:function(){
            alert("请求完成 ")
        },
        error:function(){
            alert("请求失败 ")
        }
    });
    
    		})
    
    $.ajax({
    			url: 'in.php',
    			type: 'GET',
    			// dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
    			data: {param1: 'value1'}
    		})
    		.done(function(data) {
    			$("p").html(data)
    		})
    		.fail(function() {
    			console.log("error");
    		})
    		.always(function() {
    			console.log("complete");
    		});
    		})
    

      

      

    ajax 请求 api 拿数据  

     

    {
        "msg": "获取成功",
        "response": {
            "data": [
                {
                    "YnPlcText": "{"Q00":"true","M14":"false","Q01":"false","M15":"false","Q02":"false","M16":"false","Q03":"false","M17":"false","Q04":"true","M20":"false","Q05":"false","M21":"false","Q06":"false","M22":"false","Q07":"true","M23":"false","Q10":"false","M24":"false","Q11":"false","M25":"false","Q12":"false","M26":"false","Q13":"true","M27":"false","Q14":"false","M30":"false","Q15":"false","M31":"false","Q16":"true","M32":"false","Q17":"false","M33":"false","Q20":"false","M34":"false","Q21":"false","M35":"false","Q22":"true","M36":"false","Q23":"false","M37":"false","Q24":"false","M40":"false","Q25":"true","M41":"false","Q26":"false","M42":"false","Q27":"false","M43":"false","Q80":"false","M44":"false","Q81":"true","M45":"false","Q82":"false","M46":"false","Q83":"false","M47":"false","Q84":"true","M50":"false","Q85":"false","M51":"false","Q86":"false","M52":"false","Q87":"false","M53":"false","Q120":"true","M54":"false","Q121":"false","M55":"false","Q122":"true","M200":"false","Q123":"false","M201":"false","Q124":"false","M202":"false","Q125":"false","M203":"false","Q126":"true","M204":"false","Q127":"false","M205":"false","I21":"true","I22":"true","Q135":"true","V1044":"428.16","V1224":"322.48","V1232":"128.81","M215":"false","M214":"false","Q133":"true","M221":"false","Q134":"true","M226":"false","M222":"false","M227":"false","M230":"false","Q161":"true","M176":"false","I25":"false","I26":"true","Q177":"false","Q162":"false","M197":"false","Q164":"false","M172":"false","Q165":"false","M56":"false","V1024":"33.77","V1028":"33.77","V1032":"20.21","V1088":"803.25","V1096":"547.91","V1104":"0.00","Q166":"false","M174":"false","V1008":"5.64","V1036":"93.34","V1112":"2230.18","M121":"false","V1060":"5.40","V1056":"13.51","V1048":"8.91","I35":"false","V1016":"0.00","V1020":"0.00","V1040":"79.23","V1120":"1803.21","M212":"false","Q137":"false","M223":"false","Q130":"true","Q131":"true","Q132":"false","Q163":"true","Q170":"false","M224":"false","M232":"false","Q175":"false","M225":"false","M231":"false","M191":"false","M66":"false","M67":"false","M70":"false","M74":"false","M75":"false","M76":"false","M77":"false","M180":"false","M181":"false","M182":"false","M184":"false","M186":"false","V1000":"5.86","M11":"true","M10":"true","M13":"false","M12":"false","M193":"true","M192":"false","M195":"false","M194":"false"}"
                }
            ],
            "dataCount": 1,
            "page": 1,
            "pageCount": 1
        },
        "success": true
    }
    

      

     setInterval(function () {
              $.ajax({
                url: 'http://140.143.250.251:8777/api/values/1',
                type: 'get',
                data:'',
                dataType: 'json',
                headers: {
                    "Content-Type": "application/json; charset=utf-8"
                },
                success(res) {
                	console.log(res)
                    var datas=res;
                    var datastring=datas.response.data[0]['YnPlcText'];
                    dataobj=JSON.parse(datastring)
                  
                    Q00=JSON.parse(dataobj['Q00']);
                    console.log("Q00的开关"+Q00)
                                                       
                            
    
                            }
                        })
    
          },2000)
    

      

     

  • 相关阅读:
    问题:sqlserver 跨服务器连接;结果:Sql Server 跨服务器连接
    SpringBoot之Servlet、Filter、Listener配置
    spring boot 使用@ConfigurationProperties
    Mysql字段属性应该尽量设置为not null
    微服务—ELK分布式日志框架
    微服务—分布式服务追踪sleuth和zipkin
    微服务—熔断器Hystrix
    @RequestBody和@ResponseBody的使用情形以及RestTemplate的http报文转换
    application/x-www-form-urlencoded和multipart/form-data
    基于JWT的token身份认证方案
  • 原文地址:https://www.cnblogs.com/nice2018/p/11366087.html
Copyright © 2011-2022 走看看