菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
83
0

jquery怎么写ajax?

原创
05/13 14:22
阅读数 1034

jquery怎么写ajax?

两种在客户端和服务器端进行请求-响应的常用方法是:GET 和 POST。

GET - 从指定的资源请求数据

POST - 向指定的资源提交要处理的数据

GET 基本上用于从服务器获得(取回)数据。注释:GET 方法可能返回缓存数据。

POST 也可用于从服务器获取数据。不过,POST 方法不会缓存数据,并且常用于连同请求一起发送数据。

(推荐学习:jQuery 教程手册

get方式一

$.get("test.cgi", { name: "John", time: "2pm" },
  function(data){
    alert("Data Loaded: " + data);
});

get方式二

$.get("test.php", function(data){
  alert("Data Loaded: " + data);
});

get方式三

$.get("test.php", { name: "John", time: "2pm" } );

get的参数应该可以放在url上,还没试过。

post方式一

$.post("test.php", { name: "John", time: "2pm" } );

post方式二

$.post("test.php", $("#testform").serialize());

post方式三

$.post("test.php", function(data){
   alert("Data Loaded: " + data);
});

ajax写法

$.ajax({
    type: "POST",
    dataType: "json",
    url: "",
    data: ""
    success: function(data){
    },
    error: function(msg){
    }
});

发表评论

0/200
83 点赞
0 评论
收藏
为你推荐 换一批