jQuery AJAX的get()方法和post()方法
1.作用
用于通过 HTTP GET 或 POST 请求从服务器请求数据
2.特点
get():从指定的资源请求数据。
①get请求可被缓存
②get请求保留在浏览器历史记录中
③get请求可被收藏为书签
④get请求不应在处理敏感数据时使用
⑤get请求有长度限制
⑥get请求只应当用于取回数据
$.get(src, function (result) {
console.log(result);
});
//向服务器传递数据 get方式
var inssrc = "http://127.0.0.1/insertUser";
var data = {name: '小黑', age: 18, sex: '男'};
$.get(inssrc, data, function (result) {
if (result.effectRows) {
console.log("数据增加成功");
}
});
post():向指定的资源提交要处理的数据。
①post请求不会被缓存
②post请求不会保留在浏览器历史记录中
③post不能被收藏为书签
④post请求对数据长度没有要求
var psrc = "http://127.0.0.1/findAll";
$.post(psrc, function (result) {
console.log(result);
})
var inspsrc = "http://127.0.0.1/postinsert";
var pdata = {name: '小红', age: 18, sex: '女'};
$.post(inspsrc, pdata, function (result) {
if (result.effectRows) {
console.log("数据增加成功");
}
});