Jquery中$.post()等相关方法的使用
来源:互联网 发布:小学生网络道德教育 编辑:程序博客网 时间:2024/05/29 16:29
1.$.post()
$.post(url,data,fn,type)
参数
url 必需,请求地址
data 必需,发送的数据参数
fn 必需,发送成功后的回调函数
type 可选,返回数据的类型。可以是:string或者json类型
eg:
$.post( // 接收数据的PHP页面 'action.php', // 传给PHP的数据,多个参数用&连接或者使用json格式数据:{a:'value1',b:'value2'} "a=value1&b=value2", function(msg){ // 这里是请求发送成功后的回调函数。 // msg是返回的数据,数据类型在type参数里定义! }, // 默认返回字符串,设置值等于json则返回json数据 type:'json',)
$.post("/TreeHoleWebs/commentLike", {comment_id:comment_id}, function(data){ if(data == 'ok'){ num++; $("#like_num_"+comment_id).html(num); }else if(data == 'have'){ alert('点赞过'); }else if(data == 'fail'){ alert('点赞失败!'); } } );
2.$.get()
$.get(url,data,fn)
参数
url 必需,请求地址
data 可选,发送的数据参数
fn 可选,发送成功后的回调函数
type 可选,返回数据的类型。可以是:string或者json类型
$.get( // 接收数据的PHP页面 'action.php', //传给PHP的数据,多个参数用&连接或者使用json格式数据:{a:'value1',b:'value2'} "a=value1&b=value2", function(msg){ //这里是get提交成功后,PHP程序返回的数据。msg是返回的数据,数据类型在type参数里定义! }, // 默认返回字符串,设置值等于json则返回json数据 type:'json',)
3.$.getJSON
$.getJSON(url,data,fn)
参数
url 必需,请求地址
data 可选,发送的数据参数
fn 可选,发送成功后的回调函数
该函数是简写的Ajax函数,等价于
$.ajax({ url: url, data: data, success: function(){ }, dataType: 'json'});
不带参数请求:
$.getJSON("test.php", function(json){ console.log(json);});
带参数请求:
$.getJSON("test.php", { name: "Ray", time: "18:00" }, function(json){ console.log(json);});
4.$.ajax
$.ajax({ type: "GET",// 请求方式 url: "test.php",// 请求url地址 data: {username:$("#username").val(), content:$("#content").val()}, dataType: "json",// 数据返回类型 success: function(data){ // 请求发送成功后执行的函数,data是返回的数据。 }, timeout: 3000,// 超时设置,如果3秒内请求无响应,则执行error定义的方法 error: function(){ // code }, async:true,// 默认设置为true,所有请求均为异步请求。})
0 0
- Jquery中$.post()等相关方法的使用
- jquery中$.post()方法使用
- 锋利的jQuery读书笔记---jQuery中Ajax--get、post等方法
- Rails2.0中如何使用jQuery的post方法?
- jquery post方法使用
- jquery中$.post()方法的简单实例
- jquery中$.post()方法的简单实例
- jquery的Post方法$.post()
- C(.net)中使用jQuery的POST方法提交中文乱码的处理
- django中使用jquery ajax post数据出现403错误的解决办法(两种方法)
- jquery使用post方法下载
- jQuery $.post() 方法使用案例
- 使用jQuery ajax post方法从Servlet获取json post方法中callback function不调用
- JQuery中ajax的相关方法总结
- jQuery中使用ajax,$.post
- jquery的get,post和ajax方法的使用
- jquery的get,post和ajax方法的使用
- jquery的get,post和ajax方法的使用
- MES - 设备故障流程、停机流程
- android VideoView的闪黑问题
- android studio 启动Android Devices Monitor 报错
- replace 所有html标签
- STL---unordered_set---学习
- Jquery中$.post()等相关方法的使用
- ButterKnife--View注入框架
- 【项目打包】用maven达成可执行jar文件
- swift(三) 数组的简单操作 (增 删 改 查)
- collapsible,cellspacing,DataGrid
- ICA/ Independent component analysis
- node.js express
- spring 集成 quartz 的配置
- java 用redis如何处理电商平台,秒杀、抢购超卖