JS用法(一)

来源:互联网 发布:数据传输线 编辑:程序博客网 时间:2024/05/17 03:26

AJAX具体用法:

实现异步请求:

1、请求失败,alert提示失败情况

2、请求成功,跳转到成功页面

$.ajax({type : "post",//请求方式url : "<%=path%>/userAuthServlet",data : {//发送给数据库的数据openId : $("#openId").val(),workNo : $("#workNo").val(),contactName : $("#contactName").val(),birthLastSixNo : $("#birthLastSixNo").val()},timeout : 10000,//单位毫秒//请求成功后的参数success : function(data) {if (data == '2') {alert("提示2");show();return;} else if (data == '3') {alert("提示3");show();return;} else {                                                                //跳转到成功页面                                                                window.location.href = "welcomeAuth.jsp?username=" + data;}},//请求超过timeout的10秒error : function(XMLHttpRequest, textStatus, errorThrown) {alert("超时");show();return;}});

计时函数:

实现10秒钟后自动隐藏DIV

function show() {document.getElementById("alertForm1").style.display = "";//10秒钟后调用hidden()方法,隐藏divsetTimeout("hidden()",10000)}function hidden() {document.getElementById("alertForm1").style.display = "none";}



0 0
原创粉丝点击