前端Ajax请求、HTTP POST请求、HTTP GET请求示例

Ajax请求

示例一

function check() {
//定义变量sendData
var sendData ={id:“123456”,status:“222”};
$.ajax({
url:basePath + ‘/getUser’,
type:‘post’,
dataType:‘json’,
contentType:“application/json”,
async:true,//异步请求
cache:false,
data:JSON.stringify(sendData),//使用变量sendData
//执行成功的回调函数
success:function(data) {
alert(data.info)
},
//执行失败或错误的回调函数
error:function(data) {
alert(“认证失败”);
}
});
}123456789101112131415161718192021

示例二

Handler中用【@RequestParam Map<String, String> map】接收前段数据

layer.open({
type: 1
,offset: “auto” //具体配置参考:http://www.layui.com/doc/modules/layer.html#offset
,id: ‘LAY_demo’ //防止重复弹出
,content: ‘

确认删除?

,btn: [ ‘确认’, ‘取消’]
,btnAlign: ‘c’ //按钮居中
,shade: 0.3 //不显示遮罩
,yes: function(){
//定义变量sendData
var sendData ={id:grid.id,user:grid.createUser};
$.ajax({
data: sendData,
url:“account/delAccount”,
dataType: “json”,
type: ‘POST’,
success:function(json) {
layer.msg(json.msg);
$(’#table’).bootstrapTable(‘refresh’, {url:‘account/query’});
}
});
layer.closeAll();
}
,btn2: function(index, layero){
layer.closeAll();
}
});123456789101112131415161718192021222324252627

示例三

$.ajax({
url: url,
data: $(’#dirForm’).serialize(),
dataType: “html”,
type: “post”,
success: function(result) {
$(’#jumpbox’).html(result);
$(’#jumpbox’).modal(‘show’);
}
});12345678910

示例四

( f u n c t i o n ( (function( (function() {
$(".reset").click(function() {
$("#search_form :text").val("");
$("#search_form ?eq(0)").prop(“checked”, “checked”);
$("#search_form select option:eq(0)").prop(“selected”, “selected”);
});

$(".delete").click(function() {
    var userId = $(this).data("userid");
    $('#sure_msg_body').html('确定要删除吗?此操作不可逆,请谨慎选择!');
    $('#sure_msgbox').modal('show');
    $("#sure_btn").unbind("click");
    $("#sure_btn").click(function() {
        $.ajax({
            url: "delete",
            data: {
                userId: userId
            },
            dataType: "json",
            type: "post",
            success: function(data) {
                if (data.status == "1") {
                    $('#msg_body').html('删除成功');
                    $('#msgbox').modal('show');
                    $("#msg_btn").click(function() {
                        window.location.href = "${stcds}/userManager/query";
                    });
                } else {
                    if (typeof data.info == "object") {
                        $('#msg_body').html(data.info[0].defaultMessage);
                        $('#msgbox').modal('show');
                    } else {
                        $('#msg_body').html(data.info);
                        $('#msgbox').modal('show');
                    }
                }
            }
        });
    });

});

});12345678910111213141516171819202122232425262728293031323334353637383940414243

POST请求

示例一

. p o s t ( &quot; .post(&quot; .post("{stcds}/dir/" + dirId + “/delete.msg”, function(result) {
$(’#jumpbox’).html(result);
$(’#jumpbox’).modal(‘show’);
});1234

示例二

KaTeX parse error: Expected '}', got 'EOF' at end of input: …ction(){ txt=(“input”).val();
$.post(“demo_ajax_gethint.asp”,{suggest:txt},function(result){
$(“span”).html(result);
});
});123456

JS常用操作

function clearValue(formId){
$("#" +formId+ " input:text").val(’’);
$("#" +formId+ " input:radio").attr(‘checked’, false);
$("#" +formId+ " input:checkbox").attr(‘checked’, false);
$("#" +formId+ " select").val(’’);
$("#dirCode").val(’’);
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值