解决ajax post提交后页面刷新且URL明文传参
使用ajax post数据,页面总是会刷新一次,然后还在浏览器地址栏带上了明文参数....
以为是代码问题,结果发现是form表单导致的自动提交...
在此记录一下~
方法有二:
- 修改form标签为div
- 阻止form表单自动提交
上jq代码:
$("button").click(function(){
layer.msg('sending data...');
$.post("test.php",$('form').serializeArray(),
function(data,status){
layer.msg(data);
});
return false;//此处阻止表单提交
});