ajax 访问一般处理程序报405,asp.net Ajax Post 请求 一般处理程序

var xml_http = null;

//修改密码

function updatepassword() {

var password1 = $("input[id='ipt_newpassword1']")[1].value;

var password2 = $("input[id='ipt_newpassword2']")[1].value;

if (password1 == "") {

alert("新密码不能为空!");

return false;

}

if (password2 == "") {

alert("确认新密码不能为空!");

return false;

}

if (password1 != password2) {

alert("两次输入密码不一致!");

return false;

}

var os = getOs();

if (os != "Firefox" && os != "Safari") {

xml_http = new ActiveXObject("Microsoft.XMLHTTP");

} else {

xml_http = new XMLHttpRequest();

}

var content = "type=" + encodeURIComponent("updatepassword") + "&password=" + encodeURIComponent(password1);

xml_http.open("POST", "/Handler/UserHandler.ashx", true);

xml_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xml_http.onreadystatechange = UpdatePasswordChanged;

xml_http.send(content);

$($("table[id='table_updatepassword']")[1]).hide();

$($("table[id='table_update']")[1]).show();

return null;

}

//修改密码状态返回

function UpdatePasswordChanged() {

if (xml_http.readyState == 4) {

if (xml_http.status == 200) {

if (xml_http.responseText == "True") {

alert("密码修改成功!");

closewindown();

} else {

alert(xmlHttp.responseText);

}

}

}

}

function getOs() {

var OsObject = "";

if (navigator.userAgent.indexOf("MSIE") > 0) {

return "MSIE"; //IE浏览器

}

if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {

return "Firefox"; //Firefox浏览器

}

if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {

return "Safari"; //Safan浏览器

}

if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {

return "Camino"; //Camino浏览器

}

if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {

return "Gecko"; //Gecko浏览器

}

}

string username = SecurityHelper.RequestFormStr("username", context.Request);

string password = SecurityHelper.RequestFormStr("password", context.Request);

bool is_successful = UserBll.Instance.UserSignIn(username, password);

if (is_successful)

{

///存储用户信息缓存

CacheHelper.SetSessionValue(CacheHelper.USERINFO_CACHE, UserBll.Instance.LoadCurrentUserInfo(username, password));

}

context.Response.Write(is_successful.ToString());

Json

using System;using System.Web;using System.Web.Script.Serialization;using System.Collections.Generic;public class handler : IHttpHandler{ public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/javascript"; context.Response.Cache.SetNoStore ( ); string name = context.Request["name"]; SortedDictionary values = new SortedDictionary(); values.Add("message", string.IsNullOrEmpty(name) ? "无名氏" : string.Format("你好 {0}, {1}", name, DateTime.Now)); context.Response.Write(new JavaScriptSerializer().Serialize(values)); }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值