用戶使用帝國(guó)CMS做了個(gè)表單提交,但是是form的轉(zhuǎn)跳頁(yè)面提示,他想做成ajax根據(jù)返回信息提示,不知道如何下手,下面織夢(mèng)361模板就給大家提供一個(gè)參考思路。

ajax提交思路代碼:
var data = $('#form').serialize(), url = $('#form').attr('action'); $.ajax({ method:"POST", url:url, data:data, }).done(function(){ alert("Thank you."); document.getElementById("form").reset(); }).fail(function(){ alert("Network went wrong, Please try again later."); });以上代碼的缺點(diǎn)就是沒(méi)有提示信息,當(dāng)有字段沒(méi)填時(shí),帝國(guó)默認(rèn)會(huì)出來(lái)個(gè)頁(yè)面提示有字段未填,用這個(gè)不會(huì)有提示,并且代碼認(rèn)為提交成功了,真正提交成功不會(huì)有問(wèn)題。
完整示范如下:
$.post("/e/member/doaction.php",{username:username,password:password,lifetime:lifetime,enews:"login", //logintobind:"0"},function(data,status){ if(data.indexOf("登錄成功") >= 0){ tishi('登陸成功,頁(yè)面跳轉(zhuǎn)中..請(qǐng)稍后',2); }else if(data.indexOf("您的用戶名或密碼有誤") >= 0){ tishi("您的用戶名或密碼有誤"); }else if(data.indexOf("審核") >= 0){ tishi("您的帳號(hào)還未通過(guò)審核!"); }else if(data.indexOf("為空") >= 0){ tishi("用戶名和密碼不能為空"); }else { tishi("登錄不成功,請(qǐng)確認(rèn)您的cookie是否已開(kāi)啟!"); }})完成。
新聞熱點(diǎn)
疑難解答
圖片精選