zoukankan      html  css  js  c++  java
  • jquery ajax 的 $.get()用法详解

    js文件

    $(document).ready(function(){
        $("form").submit(function(event) {event.preventDefault()})//取消submit的默认行为
        $("form input[type='submit']").click(function(){
            var url = $('form').attr('action'); // 取Form中要提交的链接
            var param = {}; // 组装发送参数
            param['name']  = $('form input[name=name]').val();
            param['age'] = $('form input[name=age]').val();
          $.get(url, param, function(dom) { $('div.get').append(dom) }) ;  // 发送并显示返回内容
        });
    })

    html文件

    <form action="ajax.php" method="get">
    Name: <input type="text" name="name" />
    Age: <input type="text" name="age" />
    <input type="submit" />
    </form>
    <div class="get">这是ajax的get方法</div>

    php文件

    error_reporting(0);
     
      if($_GET["name"]=="kitty")
    {
         
        $name= "you are the lucky";
    }
    else
    $name=$_GET["name"];
    $age=$_GET["age"];
    echo "<div>   ".$name."   ".$age."</div>";
  • 相关阅读:
    模拟Promise
    js 重写concat
    js 重写 slice
    es6继承
    es5 简单继承
    iterator 和yield的关系
    iterator接口 ...和for of依赖的关键
    e.offsetX,Y到底是相对于谁
    mysql alter修改数据库表结构用法
    mysql修改表结构
  • 原文地址:https://www.cnblogs.com/leejersey/p/3906730.html
Copyright © 2011-2022 走看看