$.get
参数
url:待载入页面的URL地址
data:待发送 Key/value 参数。
callback:载入成功时回调函数。
type:返回内容格式,xml, html, script, json, text, _default。
写法 json
$.get(
"webdata/get_1.ashx",
{},
function(data) {
var tt = "";
$.each(data, function(k, v) {
tt += k + ":" + v + "<br/>";
})
$("#divmessage").html(tt);
},
"json"
);
参数
url:发送请求地址。
data:待发送 Key/value 参数。
callback:发送成功时回调函数。
type:返回内容格式,xml, html, script, json, text, _default。
写法 json
//向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"
);区别:
1、get 是一般用户从服务中获取数据所发送的请求,post是向服务提交数据所发送请求
2、get处理的数据量比较小,一般为2kb,而post处理的数据量无限,所以从效率来说,get比post好
3、get的安全性没有post的安全性高,一般提交重要的数据使用post
本人一般都使用$.ajax,因为错误时有处理函数!
320

被折叠的 条评论
为什么被折叠?



