jQuery.post(url,[data],[callback])
来源:互联网 发布:局网络管理办法 编辑:程序博客网 时间:2024/05/16 10:45
本文转载于:http://www.cnblogs.com/bynet/archive/2010/01/04/1638692.html
jQuery.post(url,[data],[callback])
通过远程 HTTP POST 请求载入信息。
这是一个简单的 POST 请求功能以取代复杂
返回值
XMLHttpRequest
参数
url (String) : 发送请求地址。
data (Map) : (可选) 待发送 Key/value 参数。
callback (Function) : (可选) 发送成功时回调函数。
实例:利用$.post()计算两个数的和及乘(返回json)的结果。
index.html页面JS代码片段:
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> $("#btn_1").click(function(){ //验证 if ($("#txt_1").val()=='' || $("#txt_2").val()=='') { alert('请输入要计算的值'); return false; } //向add.ashx请求结果 $.post('Enumerate/add.ashx',{ //参数一 num1: $('#txt_1').val(), //参数二 num2: $("#txt_2").val() }, //回调函数 function(theback) { //输出结果 $("#span_1").text(theback); }, //返回类型 "text" ); });
add.ashx页面代码(计算并返回结果):
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><%@ WebHandler Language="C#" Class="add" %>using System;using System.Web;public class add : IHttpHandler { public void ProcessRequest (HttpContext context) { //返回类型 context.Response.ContentType = "text/html"; //接收参数 int iNum1, iNum2; int.TryParse(context.Request["num1"].ToString(),out iNum1); int.TryParse(context.Request["num2"].ToString(),out iNum2); //计算并返回结果 context.Response.Write("结果:"+(iNum1+iNum2).ToString()); } public bool IsReusable { get { return false; } }}
$.post()返回json方式用法:
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$("#btn_2").click(function(){ //验证 if ($("#txt_3").val()=='' || $("#txt_4").val()=='') { alert('请输入要计算的值'); return false; } //向multiply.ashx请求结果 $.post('Enumerate/multiply.ashx',{ //参数一 num1: $('#txt_3').val(), //参数二 num2: $("#txt_4").val() }, //回调函数 function(theback) { //输出结果 $("#div_2").html('第一个数:'+theback.num1+'<br />'+'第二个数:'+theback.num2+'<br />'+'算法类型:'+theback.type+'<br />'+'计算结果:'+theback.result); }, //返回类型 "json" ); });
C#返回json方式代码(multiply.ashx页面):
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> context.Response.ContentType = "application/json"; int iNum1, iNum2; int.TryParse(context.Request["num1"].ToString(), out iNum1); int.TryParse(context.Request["num2"].ToString(), out iNum2); context.Response.Write("{num1: '" + iNum1.ToString() + "',num2: '" + iNum2.ToString() + "',type: 'enumerate',result: '" + (iNum1 * iNum2).ToString() + "'}");
0 0
- jQuery.post(url,[data],[callback])
- jQuery.post(url, [data], [callback], [type])
- jQuery Ajax请求-jQuery.post(url, [data], [callback], [type])
- jQuery.getJSON(url, [data], [callback])
- jQuery load(url, [data], [callback])
- jQuery.post( url, [data], [callback], [type] ) : 使用POST方式来进行异步请求
- XMLHttpRequestjQuery.post(url, [data], [callback], [type])
- jQueryAjax请求-jQuery.getJSON(url, [data], [callback])
- jQuery.get(url,[data],[callback])的[data]的作用
- jQuery Ajax请求-jQuery.get(url, [data], [callback], [type])
- $.post(url, params, callback)
- $.get( url, [data], [callback] )
- jQuery.getJSON(url, [data], [callback])[通过url,文件。txt,带参数三种方式](十三)
- learning jQuery 学习笔记十五(+jQuery 1.4.1 API)-- AJAX----load(url, [data], [callback])
- 使用jQuery.get(url,[data],[callback])不能获取返回的页面XML内容
- 函数原型:$.post(url, params, callback)
- jQuery Ajax请求-jQuery.getScript(url, [callback])
- AJAX - $.post(url,data,function,type)
- 烧掉43亿的家装O2O未来会成什么样?
- COCOS学习笔记--内存管理(二)-PoolManager类和AutoreleasePool类的讲解
- 网络服务器开发总结
- linux的free命令详解
- Python终端中敲击方向键显示「^[[C^[[D」如何修复?
- jQuery.post(url,[data],[callback])
- Android 学习之路(源码网站及书籍)
- 【代码笔记】iOS-底下滚动,上面标题栏也会跟着变动
- Linux下程序的Profile工具
- g's'da'j'k
- ios获取app当前的版本号
- pmap学习:系统测试中怎么确定内存泄露(memory leak)
- 谈薪:不要接受对方第一次开价!
- UNIX -- NTP 命令