標籤:style class blog code java http
JavaScript 中的ajax提交請求
$.ajax({// 提交地址 url: "", // 提交的資料 data: { key1: value1, key2: value2, key3: value3, key4: value4 },// 提交前事件 beforeSend: function () { login.hide(); showInfo.html(loginInfo); },// 提交方式 type: "POST",// 提交的資料類型 dataType: "json",// 提交成功後事件 success: function (result) { if (result.State.toString() == "success" && result.IsLogin.toString() == "1") { showInfo.addInfoMsg("登入成功!正在跳轉. . ."); window.location.href = "/Default.aspx"; } else { login.show(); showInfo.addShowMsg(result.exMsg.toString()); } },// 提交錯誤時間 error: function (httpRequest, textStatus, errorThrown) { showInfo.addShowMsg("系統出錯,請重新登入!"); login.show(); } });
返回的資料格式:
// 返回的資料格式 一下 var returnInfo = "\"State\":\"{0}\",\"IsLogin\":\"{1}\",\"exMsg\":\"{2}\"";context.Response.Write("{" + String.Format(returnInfo, "success", "1", "登入成功!") + "}");context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "使用者名稱不可為空") + "}");context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "密碼不可為空") + "}");context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "您沒有登入系統的許可權,請聯絡貴公司管理員.") + "}");context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "非法登陸," + ex.Message + "}"));