layui发送ajax请求
html:<form class="layui-form" action="" lay-filter="form-group"><div class="layui-form-item"><div class="layui-inline"><label class="layui-form-label">xxx</label><div
·
html:
<form class="layui-form" action="" lay-filter="form-group">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">xxx</label>
<div class="layui-input-inline">
<input type="xxx" name="xxx" class="layui-input">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">xxxx</label>
<div class="layui-input-block">
<input type="radio" name="111" value="111" title="111" checked="">
<input type="radio" name="222" value="222" title="222">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="form-submit">提交</button>
</div>
</div>
</form>
js:
<script>
form.on('submit(form-submit)', function (inputData) {
console.log("inputData:",inputData);
$.ajax({
url:"xxxxx",
data:{'xxx':xxx,'xx':xxx},
type:"post",
dataType:"json",
headers : {'Content-Type' : 'application/json;charset=utf-8'}, //接口json格式
success:function(data){
console.log(data);
layer.alert(JSON.stringify(data), {
title: data
});
},
error:function(data){
layer.alert(JSON.stringify(data), {
title: data
});
}
});
</script>
get:
将post方式改成get方式,url改成对应的地址即可
更多推荐
已为社区贡献2条内容
所有评论(0)