怎么使用jquery调用.ashx文件jquery获取返回值值

jQuery获取一般处理程序(ashx)的JSON数据 - ASP.NET技巧 - 大学IT网
当前位置: >
> jQuery获取一般处理程序(ashx)的JSON数据
关键词:&&阅读(3446) 赞(19)
[摘要]本文是对jQuery获取一般处理程序(ashx)的JSON数据的讲解,对学习ASP.NET编程技术有所帮助,与大家分享。
昨天有在开发的软件生产线生产流程,RFID扫描IC卡的数据,当中有用到jQuery获取一般处理程序(ashx)的JSON数据。今有把它写成一个小例子,望需要的网友能参考。
在网站中,创建一个一般应用程序ashx:
命名空间:
using System.D
using System.Collections.G
using System.Web.Script.S
输出的内容类型:
context.Response.ContentType = "application/json";
宣告一个变量,是为了那些可以跨域访问:
string callback = context.Request["callback"];
上面的代码示例中,另外还有一个方法DataTableToJSON(),你可以写成一个公用的方法,因为软件中会有很多地方会用到。
好的,为了在aspx能显示ashx输出的数据,创建一个网页:
网页运行结果:
相关ASP.NET技巧推荐
暂时没有相关推荐> jquery ajax ashx返回值为空求解解决办法
jquery ajax ashx返回值为空求解解决办法
xiechao851212 & &
发布时间: & &
浏览:15 & &
回复:0 & &
悬赏:0.0希赛币
jquery ajax ashx返回值为空求解各位大神帮我看个问题,
&body&onload="funStateJudge();"&
  function&funStateJudge()&{
&&&&$.ajax({
&&&&&&&&url:&"Service/PassWordJudge.asmx/StateJudge",
&&&&&&&&contentType:&"application/json",
&&&&&&&&dataType:&"json",
&&&&&&&&data:&"{}",
&&&&&&&&type:&"POST",
&&&&&&&&success:&function&(json)&{
&&&&&&&&&&&&//alert(json.d);//输出结果
&&&&&&&&&&&&if&(json.d&==&"1")&{
&&&&&&&&&&&&&&&&document.getElementById("divState").style.visibility&=&"visible";
&&&&&&&&&&&&&&&&funGetUserData();&//显示获取登陆信息
&&&&&&&&&&&&}
&&&&&&&&&&&&else&{
&&&&&&&&&&&&&&&&funShowpnlLogin();
&&&&&&&&&&&&&&&&document.getElementById("divState").style.visibility&=&"hidden";
&&&&&&&&&&&&}
&&&&&&&&},
&&&&&&&&error:&function&(x,&e)&{
&&&&&&&&&&&&alert(x.responseText);
&&&&&&&&&&&&errorSolve();&//异常处理
  function&funGetUserData()&{
&&&&$.ajax({
&&&&&&&&url:&"Service/GetSessionValue.ashx",
&&&&&&&&contentType:&"application/json",
&&&&&&&&dataType:&"json",
&&&&&&&&type:&"POST",
&&&&&&&&data:&"{}",
&&&&&&&&success:&function&(json)&{
&&&&&&&&&&&&//&&&&&&&&&&&&&alert(json.UserName);&//输出结果
&&&&&&&&&&&&//&&&&&&&&&&&&&alert(json.UserAccount);&//输出结果
&&&&&&&&&&&&document.getElementById("lbtnUserName").innerText&=&json.UserN&//显示输出用户姓名
&&&&&&&&&&&&document.getElementById("lbtnUserAccount").innerText&=&json.UserA&//显示输出用户帐号
&&&&&&&&},
&&&&&&&&error:&function&(x,&e)&{
&&&&&&&&&&&&funGetUserData();&//重复调用,方式页面加载时调用失败{这里两个页面之间来回跳转时无规律的出现失败现象,返回结果为空,反复调用即可得到返回值。。求解}
  public&void&ProcessRequest(HttpContext&context)
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&当前位置: >
Jquery调用从ashx文件返回的jsonp格式的数据处理实例
时间: 08:38 来源:互联网 作者:源码搜藏 浏览:
开发环境:vs2010+jquery-1.4.min.js 解决问题:网上代码比较少,好多调试不通,返回数据不用json而用jsonp主要考虑解决跨域问题 开发步骤:打开VS2010,新建一web站点,保存位置选择D:\Website1;添加新项,选择一般处理程序,命名cmdHandler.添加新项,
开发环境:vs2010+jquery-1.4.min.js
解决问题:网上代码比较少,好多调试不通,返回数据不用json而用jsonp主要考虑解决跨域问题
开发步骤:打开VS2010,新建一web站点,保存位置选择D:\Website1;添加新项,选择一般处理程序,命名cmdHandler.添加新项,选择HTML页,命名为testAshx.网上下载jquery-1.4.min.js拷贝到web站点中
项目相关代码和运行截图如下:
1、testAshx.htm代码如下:
&!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Transitional//EN& &http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&&
&html xmlns=&http://www.w3.org/1999/xhtml&&
&title&Jquery调用ashx文件返回的jsonp格式数据实例&/title&
&script type=&text/javascript& src=&jquery-1.4.min.js&&&/script&
&&& &div id=&Div1&& &/div&
&&& &div id=&Div2&& &/div&
&&& &div id=&Div3&& &/div&
&&& &div id=&Div4&& &/div&
&&& &script type=&text/javascript& &
&&&&&&& //回调函数1
&&&&&&& function success_jsonpCallback11(data) {
&&&&&&&&&&& var $ul = $(&&ul&&/ul&&);
&&&&&&&&&&& $.each(data, function (i, v) {
&&&&&&&&&&&&&&& $(&&li/&&).text(v[&id&] + & & + v[&name&]).appendTo($ul)
&&&&&&&&&&& });
&&&&&&&&&&& $(&#Div2&).html($ul);
&&&&&&& //回调函数2
&&&&&&& function success_jsonpCallback22(data) {
&&&&&&&&&&& var $ul = $(&&ul&&/ul&&);
&&&&&&&&&&& $.each(data, function (i, v) {
&&&&&&&&&&&&&&& $(&&li/&&).text(v[&OrderID&] + & & + v[&CustomerID&]).appendTo($ul)
&&&&&&&&&&& });
&&&&&&&&&&& $(&#Div4&).html($ul);
&&&&&&& //页面加载完成后执行下面代码
&&&&&&& $(document).ready(function () {
&&&&&&&&&&& //读取Ashx文件中直接返回的字符串
&&&&&&&&&&& $.ajax({
&&&&&&&&&&&&&&& url: 'cmdHandler.ashx',
&&&&&&&&&&&&&&& data: { StatusCode: 1 },
&&&&&&&&&&&&&&& dataType: &jsonp&,
&&&&&&&&&&&&&&& jsonp: &jsonpcallback&,
&&&&&&&&&&&&&&& success: function (data) {
&&&&&&&&&&&&&&&&&&& var $ul = $(&&ul&&/ul&&);
&&&&&&&&&&&&&&&&&&& $.each(data, function (i, v) {
&&&&&&&&&&&&&&&&&&&&&&& $(&&li/&&).text(v[&id&] + & & + v[&name&]).appendTo($ul)
&&&&&&&&&&&&&&&&&&& });
&&&&&&&&&&&&&&&&&&& $(&#Div1&).html($ul);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& });
&&&&&&&&&&& //读取Ashx文件中直接返回的字符串带回调函数名称
&&&&&&&&&&& $.ajax({
&&&&&&&&&&&&&&& type: &get&,
&&&&&&&&&&&&&&& async: false,
&&&&&&&&&&&&&&& url: &cmdHandler.ashx&,
&&&&&&&&&&&&&&& data: { StatusCode: 1 },
&&&&&&&&&&&&&&& dataType: &jsonp&,
&&&&&&&&&&&&&&& jsonp: &jsonpcallback&, //传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(默认为:callback)&
&&&&&&&&&&&&&&& jsonpCallback: &success_jsonpCallback1&, //自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名&
&&&&&&&&&&&&&&& success: function (json) {
&&&&&&&&&&&&&&&&&&& //在此之前若没有定义回调函数success_jsonpCallback1则执行下面的代码
&&&&&&&&&&&&&&&&&&& var $ul = $(&&ul&&/ul&&);
&&&&&&&&&&&&&&&&&&& $.each(json, function (i, v) {
&&&&&&&&&&&&&&&&&&&&&&& $(&&li/&&).text(v[&id&] + & & + v[&name&]).appendTo($ul)
&&&&&&&&&&&&&&&&&&& });
&&&&&&&&&&&&&&&&&&& $(&#Div2&).html($ul);
&&&&&&&&&&&&&&& },
&&&&&&&&&&&&&&& error: function () {
&&&&&&&&&&&&&&&&&&& alert('fail');
&&&&&&&&&&&&&&& }
&&&&&&&&&&& });
&&&&&&&&&&& //读取Ashx文件中返回的数据库字符串
&&&&&&&&&&& $.ajax({
&&&&&&&&&&&&&&& type: &get&,
&&&&&&&&&&&&&&& async: false,
&&&&&&&&&&&&&&& url: &cmdHandler.ashx&,
&&&&&&&&&&&&&&& data: { StatusCode: 2 },
&&&&&&&&&&&&&&& dataType: &jsonp&,
&&&&&&&&&&&&&&& jsonp: &jsonpcallback&,
&&&&&&&&&&&&&&& success: function (json) {
&&&&&&&&&&&&&&&&&&& var $ul = $(&&ul&&/ul&&);
&&&&&&&&&&&&&&&&&&& $.each(json, function (i, v) {
&&&&&&&&&&&&&&&&&&&&&&& $(&&li/&&).text(v[&OrderID&] + & & + v[&CustomerID&]).appendTo($ul)
&&&&&&&&&&&&&&&&&&& });
&&&&&&&&&&&&&&&&&&& $(&#Div3&).html($ul);
&&&&&&&&&&&&&&& },
&&&&&&&&&&&&&&& error: function () {
&&&&&&&&&&&&&&&&&&& alert('fail');
&&&&&&&&&&&&&&& }
&&&&&&&&&&& });
&&&&&&&&&&& //读取Ashx文件中返回的数据库字符串带回调函数名称
&&&&&&&&&&& $.ajax({
&&&&&&&&&&&&&&& type: &get&,
&&&&&&&&&&&&&&& async: false,
&&&&&&&&&&&&&&& url: &cmdHandler.ashx&,
&&&&&&&&&&&&&&& data: { StatusCode: 2 },
&&&&&&&&&&&&&&& dataType: &jsonp&,
&&&&&&&&&&&&&&& jsonp: &jsonpcallback&, //传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(默认为:callback)&
&&&&&&&&&&&&&&& jsonpCallback: &success_jsonpCallback2&, //自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名&
&&&&&&&&&&&&&&& success: function (json) {
&&&&&&&&&&&&&&&&&&& //在此之前若没有定义回调函数success_jsonpCallback2则执行下面的代码
&&&&&&&&&&&&&&&&&&& var $ul = $(&&ul&&/ul&&);
&&&&&&&&&&&&&&&&&&& $.each(json, function (i, v) {
&&&&&&&&&&&&&&&&&&&&&&& $(&&li/&&).text(v[&OrderID&] + & & + v[&CustomerID&]).appendTo($ul)
&&&&&&&&&&&&&&&&&&& });
&&&&&&&&&&&&&&&&&&& $(&#Div4&).html($ul);
&&&&&&&&&&&&&&& },
&&&&&&&&&&&&&&& error: function () {
&&&&&&&&&&&&&&&&&&& alert('fail');
&&&&&&&&&&&&&&& }
&&&&&&&&&&& });
&&&&&&&&&&& /* 回调函数写在末尾时候不起作用
&&&&&&&&&&& function success_jsonpCallback(data) {
&&&&&&&&&&&&&&& alert(&测试成功&);
&&&&&&&&&&& }&
&&&&&&&&&&& */
2、cmdHandler代码如下:
&%@ WebHandler Language=&C#& Class=&cmdHandler& %&
using System.W
//添加引用
using System.D
using System.Data.SqlC
using System.T
public class cmdHandler : IHttpHandler {
&&& public void ProcessRequest(HttpContext context)
&&&&&&& context.Response.ContentType = &text/plain&;
&&&&&&& string StatusCode = context.Request.QueryString[&StatusCode&];
&&&&&&& switch (StatusCode)
&&&&&&&&&&& case &1&://返回测试用的组合字符串
&&&&&&&&&&&&&&& context.Response.Write(getFormatString(context));
&&&&&&&&&&&&&&&
&&&&&&&&&&& case &2&://返回查询数据库得到的组合字符串
&&&&&&&&&&&&&&& context.Response.Write(GetDbString(context));
&&&&&&&&&&&&&&&
&&& #region 测试用的组合字符串
&&& public string getFormatString(HttpContext context)
&&&&&&& string strReturn = &&;
&&&&&&& string jsonp = context.Request[&jsonpcallback&];
&&&&&&& string str = &[{\&id\&:\&1\&,\&name\&:\&张三\&},{\&id\&:\&2\&,\&name\&:\&李四\&}]&;
&&&&&&& strReturn = jsonp + &(& + str + &)&;
&&&&&&& return strR
&&& #endregion
&&& #region 查询数据库得到组合字符串
&&& public string GetDbString(HttpContext context)
&&&&&&& string strReturn = &&;
&&&&&&& string strConn = &server=.;database=uid=pwd=123456;&;//数据库连接字符串
&&&&&&& string strFun = context.Request[&jsonpcallback&];//传递参数
&&&&&&& StringBuilder strJsonData = new StringBuilder();//拼接json所有格式
&&&&&&& StringBuilder strJsonMsgData = new StringBuilder();//拼接json内容
&&&&&&& string sqlText = &select top 3 * from Orders&;//查询数据表语句
&&&&&&& DataSet ds = new DataSet();
&&&&&&& SqlConnection mySqlConnection = new SqlConnection();
&&&&&&& mySqlConnection.ConnectionString = strC
&&&&&&& try
&&&&&&&&&&& mySqlConnection.Open();
&&&&&&&&&&& SqlCommand mySqlCommand = new SqlCommand();
&&&&&&&&&&& mandText = sqlT
&&&&&&&&&&& mySqlCommand.Connection = mySqlC
&&&&&&&&&&& SqlDataAdapter da = new SqlDataAdapter(mySqlCommand);
&&&&&&&&&&& da.Fill(ds);
&&&&&&&&&&& DataTable dt = ds.Tables[0];
&&&&&&&&&&& if (dt.Rows.Count & 0)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& strJsonData.AppendFormat(&{0}([&, strFun);//json begin
&&&&&&&&&&&&&&& foreach (DataRow row in dt.Rows)//得到行集合
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& strJsonMsgData.Append(&{\&OrderID\&& + &:& + &\&& + row[&OrderID&].ToString() + &\&& + &,\&CustomerID\&& + &:& + &\&& + row[&CustomerID&].ToString() + &\&}& + &,&);
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& strJsonData.Append(strJsonMsgData.ToString().TrimEnd(','));
&&&&&&&&&&&&&&& strJsonData.Append(&])&);//json end
&&&&&&&&&&&&&&& strReturn = strJsonData.ToString();
&&&&&&&&&&& }
&&&&&&&&&&& else
&&&&&&&&&&& {
&&&&&&&&&&&&&&& strJsonData.AppendFormat(&{0}([&, strFun);//json begin
&&&&&&&&&&&&&&& strJsonData.Append(&])&);//json end
&&&&&&&&&&&&&&& strReturn = strJsonData.ToString();
&&&&&&&&&&& }
&&&&&&& catch
&&&&&&& finally
&&&&&&&&&&& mySqlConnection.Close();
&&&&&&& return strR
&&& #endregion
&&& public bool IsReusable
&&&&&&& get
&&&&&&&&&&&
3、jquery-1.4.min.js文件不贴代码了,网上自己下,也可以使用更高版本的jquery.js文件
4、IE和火狐运行截图如下:温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
坦诚.直率.开朗.认真
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
2.首先在该页面的后台文件demos.aspx.cs中添加引用。using System.Web.S3.无参数的方法调用.大家注意了,这个版本不能低于.net framework 2.0。2.0已下不支持的。后台代码:[WebMethod] & &&public static string SayHello() & &&{ & &&& & &return "Hello Ajax!"; & &&} & &JS代码:$(function() { & &&& & $("#btnOK").click(function() { & &&& & & & $.ajax({ & &&& & & & & & //要用post方式 & & && & & & & & type: "Post", & &&& & & & & & //方法所在页面和方法名 & & && & & & & & url: "Demo.aspx/SayHello", & &&& & & & & & contentType: "application/ charset=utf-8", & &&& & & & & & dataType: "json", & &&& & & & & & success: function(data) { & &&& & & & & & & & //返回的数据用data.d获取内容 & & && & & & & & & & alert(data.d); & &&& & & & & & }, & &&& & & & & & error: function(err) { & &&& & & & & & & & alert(err); & &&& & & & & & } & &&& & & & }); & &&& &&& & & & //禁用按钮的提交 & & && & & & & &&& & }); & &&}); &&页面代码:& & &form id="form1" runat="server"&& & &div&& & & & &asp:Button ID="btnOK" runat="server" Text="验证用户" /&& & &/div&& & &/form&运行效果如下:&3.有参数方法调用后台代码:[WebMethod] & &&public static string GetStr(string str, string str2) & &&{ & &&& & return str + str2; & &&}&JS代码:$(function() { & &&& & $("#btnOK").click(function() { & &&& & & & $.ajax({ & &&& & & & & & type: "Post", & &&& & & & & & url: "demo.aspx/GetStr", & &&& & & & & & //方法传参的写法一定要对,str为形参的名字,str2为第二个形参的名字 & & && & & & & & data: "{'str':'我是','str2':'XXX'}", & &&& & & & & & contentType: "application/ charset=utf-8", & &&& & & & & & dataType: "json", & &&& & & & & & success: function(data) { & &&& & & & & & & & //返回的数据用data.d获取内容 & & && & & & & & & & & alert(data.d); & &&& & & & & & }, & &&& & & & & & error: function(err) { & &&& & & & & & & & alert(err); & &&& & & & & & } & &&& & & & }); & &&& &&& & & & //禁用按钮的提交 & & && & & & & &&& & }); & &&}); & &运行效果如下:4.返回数组方法后台代码:[WebMethod] & &&public static List&string& GetArray() & &&{ & &&& & List&string& li = new List&string&(); & &&& &&& & for (int i = 0; i & 10; i++) & &&& & & & li.Add(i + ""); & &&& &&& & & &&} & &JS代码:$(function() { & &&& & $("#btnOK").click(function() { & &&& & & & $.ajax({ & &&& & & & & & type: "Post", & &&& & & & & & url: "demo.aspx/GetArray", & &&& & & & & & contentType: "application/ charset=utf-8", & &&& & & & & & dataType: "json", & &&& & & & & & success: function(data) { & &&& & & & & & & & //插入前先清空ul & & && & & & & & & & $("#list").html(""); & &&& &&& & & & & & & & //递归获取数据 & & && & & & & & & & $(data.d).each(function() { & &&& & & & & & & & & & //插入结果到li里面 & & && & & & & & & & & & $("#list").append("&li&" + this + "&/li&"); & &&& & & & & & & & }); & &&& &&& & & & & & & & alert(data.d); & &&& & & & & & }, & &&& & & & & & error: function(err) { & &&& & & & & & & & alert(err); & &&& & & & & & } & &&& & & & }); & &&& &&& & & & //禁用按钮的提交 & & && & & & & &&& & }); & &&});&页面代码:&form id="form1" runat="server"&&div&& & &asp:Button ID="btnOK" runat="server" Text="验证用户" /&&/div&&ul id="list"&&/ul&&/form&//验证用户登陆& & & & $(function () {& & & & & & $("#aLogin").click(function () {& & & & & & & & $.ajax({& & & & & & & & & & type: "Post",& & & & & & & & & & url: "Home.aspx/Login",& & & & & & & & & & data: { 'username': $("#Home_Index1_username").val(), 'userPWD': $("#userPWD").val(),&'action': 'Login', 'checked': $("#Remember_my").attr("checked"), 'Code': $("#Code").val() },& & & & & & & & & & //contentType: "application/ charset=utf-8",& & & & & & & & & & //dataType: "json",& & & & & & & & & & success: function (data) {& & & & & & & & & & & & alert(data);& & & & & & & & & & & & window.location.reload(true); & & & & & &&& & & & & & & & & & & &&& & & & & & & & & & },& & & & & & & & & & error: function (err) {& & & & & & & & & & & & alert(err);& & & & & & & & & & }& & & & & & & & });& & & & & & });& & & & });&div class="top" id="divmemberlogin" style="display:&%= strloginArea%&;"&& & & & &span &用户名:&/span&& & & & &input type="text" class="word" id="username" runat="server" &onkeyup="textChanged(event)" /&& & & & &span&密码:&/span&& & & & &input type="password" class="word" id="userPWD" onkeyup="textChanged(event)" &/&& & & & &input maxlength="4" id="Code" type="text" style="width: 100float:" placeholder="验证码"&class="word" onkeyup="textChanged(event)" /&& & & & & & & & & & &span style="width:75"&&img src="/Frame/VerifyCode.ashx" id="Verify_codeImag"&width="70" height="28" alt="点击切换验证码"& & & & & & & & & & & & title="点击切换验证码" style="cursor: margin-left:-5" &onclick="ToggleCode(this.id, '/Frame/VerifyCode.ashx');" /&&/span&& & & & &%--&span&验证码:&/span&& & & & &input type="text" class="word" /&--%&& & & & &a id="aLogin" class="Login" style="text-decoration: cursor:" &OnClick="btn_Login"&登录&/a&& & & & &%--&asp:Button ID="aLogin" CssClass="Login" Text="登录" runat="server" &BorderStyle="None"&OnClick="aLogin_Click" &/&--%&& & & & &input id="Remember_my" type="checkbox" class="Remember_my" &/&&span id="spanrememberme"&记住我&/span&& & & & &%--&span id="spanrememberme"& &input class="Remember_my" type="checkbox" checked="checked"&runat="server" id="agree_userterm" name="auto_login"&记住我&/span&--%&&a href="http://ayue05./blog/FindPWD.aspx"&忘记密码?&/a&& & & & &div class="right"&&a href="http://ayue05./blog/register.aspx"&注册&/a&&a href="http://ayue05./blog/#"&新用户?从这里开始&/a&&/div&& & &/div&#region 登录处理(用户名,密码,是否记住我,验证码)& & & & public string Login(string username, string userPWD, string action, string strchecked, string Code)& & & & {& & & & & & var result = string.E& & & & & & if (username != null && userPWD != null && Code != null)& & & & & & {& & & & & & & & if (Code.ToLower() == Context.Session["dt_session_code"].ToString().ToLower())& & & & & & & & {& & & & & & & & & & Member_InfoIBLL ibllmember = new Member_InfoBLL();& & & & & & & & & & StringBuilder strmem = new StringBuilder();& & & & & & & & & & strmem.Append(" and memberName='" + username + "' and pwd='" + Md5Helper.MD5(userPWD,&32) + "'");& & & & & & & & & & Member_Info memberinfo = ibllmember.GetEntityWhere(strmem);& & & & & & & & & & //IList memberlist =new Member_InfoBLL().GetListWhere(" and memberName='" + username +&"' and pwd='" + Md5Helper.MD5(userPWD, 32)+"'"); & & & & & & & & & && & & & & & & & & & if (memberinfo != null)& & & & & & & & & & {& & & & & & & & & & & & //设置SESSION& & & & & & & & & & & & Session["index_memberinfo"] =& & & & & & & & & & & & #region 记录Cookie& & & & & & & & & & & & if (strchecked == "checked")& & & & & & & & & & & & {& & & & & & & & & & & & & & //记住用户名& & & & & & & & & & & & & & HttpCookie CookieUsersName = new HttpCookie("Login_UsersName", username);& & & & & & & & & & & & & & Response.Cookies.Add(CookieUsersName);& & & & & & & & & & & & & & //十天免登录& & & & & & & & & & & & & & //Std.Page.StdUserControl.setSaveTime = 10;& & & & & & & & & & & & }& & & & & & & & & & & & else& & & & & & & & & & & & {& & & & & & & & & & & & & & HttpCookie GetCookieUsersName = Request.Cookies["Login_UsersName"];& & & & & & & & & & & & & & if (GetCookieUsersName != null && !string.IsNullOrEmpty(GetCookieUsersName.Value))& & & & & & & & & & & & & & {& & & & & & & & & & & & & & & & GetCookieUsersName.Expires = DateTime.Now.AddDays(-1);& & & & & & & & & & & & & & & & Response.Cookies.Add(GetCookieUsersName);& & & & & & & & & & & & & & }& & & & & & & & & & & & }& & & & & & & & & & & & StdUserControl.CurrentUser =& & & & & & & & & & & & #endregion& & & & & & & & & & & & Member_level_infoIBLL ibllmemberlevel = new Member_level_infoBLL();& & & & & & & & & & & & StringBuilder strmemlevel = new StringBuilder();& & & & & & & & & & & & strmemlevel.Append(" and levelId='" + memberinfo.levelId.ToString() + "'");& & & & & & & & & & & & string strlevelname = ibllmemberlevel.GetEntityWhere(strmemlevel).levelName.ToString();& & & & & & & & & & & & StringBuilder strmember = new StringBuilder();& & & & & & & & & & & & strmember.Append("&div class='task'&&div class='img'&&img width='75' height='60'&src='http://ayue05./blog/images/pic02.jpg'&&/div&&div class='right'&&p&&span class='red'&" + memberinfo.memberName.ToString() +&"&/span&(" + (memberinfo.isAduit.ToString() == "1" ? "已激活" : "未激活") + ")&/p&&p&上次登录时间:&/p&&p&" + memberinfo.lastLoginDate.ToString().Substring(0, memberinfo.lastLoginDate.ToString().IndexOf("&")) + "&/p&&/div&&/div&");& & & & & & & & & & & & strmember.Append("&p&账户余额:&span class='red'&¥" + memberinfo.Balance.ToString()&+ "&/span&&a class='blue' href='http://ayue05./blog/#'&账户设置&/a&&/p&");& & & & & & & & & & & & strmember.Append("&p&积分:&span class='red'&" + memberinfo.Integration.ToString() +&"&/span&&a class=' blue' href='http://ayue05./blog/#'&兑换&/a&&/p&");& & & & & & & & & & & & strmember.Append("&p&发布点个数:&span class='red'&97.195&/span&个&/p&");& & & & & & & & & & & & strmember.Append("&p&收藏点个数:&span class='red'&8&/span&个&/p&");& & & & & & & & & & & & strmember.Append("&p&VIP:" + (strlevelname == "VIP会员" ? "是" : "否") + "&/p&");& & & & & & & & & & & & strmember.Append("&p&信托卡:单钻信托卡&/p&");& & & & & & & & & & & & strmember.Append("&p&商保:否&/p&");& & & & & & & & & & & & strmember.Append("&p class='task_bom'&&a href='http://ayue05./blog/#'&发布任务&/a&&/p&");& & & & & & & & & & & & strmember.Append("");& & & & & & & & & & & & //result = strmember.ToString();& & & & & & & & & & & & Session["index_memberinfoArea"] = strmember.ToString();& & & & & & & & & & & & result = "登陆成功";& & & & & & & & & & }& & & & & & & & & & else& & & & & & & & & & {& & & & & & & & & & & & Session["index_memberinfoArea"] = "";& & & & & & & & & & & & result = "登陆失败";& & & & & & & & & & } & & & & & & & & & && & & & & & & & }& & & & & & & & else& & & & & & & & {& & & & & & & & & & result = "验证码错误";& & & & & & & & }& & & & & & }& & & & & & else& & & & & & { & & & & & & & && & & & & & & & result= "请输入完整";& & & & & & }& & & & & & Response.Write(result);& & & & & & Response.End();& & & & & && & & & }& & & & #endregionhome.aspx.csusing Susing System.Collections.Gusing System.Lusing System.Wusing System.Web.UI;using System.Web.UI.WebCusing System.Web.Susing System.Tusing Shualo.Busing Shualo.Eusing Shualo.IBusing DotNet.Kusing System.Cusing DotNet.Uusing Shualo.Pnamespace Shualo.WEB.Home{& & public partial class Home : System.Web.UI.Page& & {& & & & public string strLoginName = string.E& & & & public string index_memberinfoArea = string.E& & & & protected void Page_Load(object sender, EventArgs e)& & & & {& & & & & & var action = Request["action"];& & & & & & switch (action)& & & & & & {& & & & & & & & case "Login":& & & & & & & & & & var name = Request["username"];& & & & & & & & & & var pws = Request["userPWD"];& & & & & & & & & & var strchecked = Request["checked"];& & & & & & & & & & var Code = Request["Code"];& & & & & & & & & & Login(name, pws, action, strchecked, Code);& & & & & & & & & && & & & & & & & case "spTaskOver":& & & & & & & & & & var memberuname = Request["memberuname"];& & & & & & & & & & spTaskOver(memberuname);& & & & & & & & & && & & & & & & & default:& & & & & & & & & && & & & & & }& & & & }& & & &&& & & & #region 登录处理(用户名,密码,是否记住我,验证码)& & & & public string Login(string username, string userPWD, string action, string strchecked, string Code)& & & & {& & & & & & var result = string.E& & & & & & if (username != null && userPWD != null && Code != null)& & & & & & {& & & & & & & & if (Code.ToLower() == Context.Session["dt_session_code"].ToString().ToLower())& & & & & & & & {& & & & & & & & & & Member_InfoIBLL ibllmember = new Member_InfoBLL();& & & & & & & & & & StringBuilder strmem = new StringBuilder();& & & & & & & & & & strmem.Append(" and memberName='" + username + "' and pwd='" + Md5Helper.MD5(userPWD, 32) + "'");& & & & & & & & & & Member_Info memberinfo = ibllmember.GetEntityWhere(strmem);& & & & & & & & & & //IList memberlist =new Member_InfoBLL().GetListWhere(" and memberName='" + username + "' and pwd='" + Md5Helper.MD5(userPWD, 32)+"'"); & & & & & & & & & && & & & & & & & & & if (memberinfo != null)& & & & & & & & & & {& & & & & & & & & & & & //设置SESSION& & & & & & & & & & & & Session["index_memberinfo"] =& & & & & & & & & & & & #region 记录Cookie& & & & & & & & & & & & if (strchecked == "checked")& & & & & & & & & & & & {& & & & & & & & & & & & & & //记住用户名& & & & & & & & & & & & & & HttpCookie CookieUsersName = new HttpCookie("Login_UsersName", username);& & & & & & & & & & & & & & Response.Cookies.Add(CookieUsersName);& & & & & & & & & & & & & & //十天免登录& & & & & & & & & & & & & & //Std.Page.StdUserControl.setSaveTime = 10;& & & & & & & & & & & & }& & & & & & & & & & & & else& & & & & & & & & & & & {& & & & & & & & & & & & & & HttpCookie GetCookieUsersName = Request.Cookies["Login_UsersName"];& & & & & & & & & & & & & & if (GetCookieUsersName != null && !string.IsNullOrEmpty(GetCookieUsersName.Value))& & & & & & & & & & & & & & {& & & & & & & & & & & & & & & & GetCookieUsersName.Expires = DateTime.Now.AddDays(-1);& & & & & & & & & & & & & & & & Response.Cookies.Add(GetCookieUsersName);& & & & & & & & & & & & & & }& & & & & & & & & & & & }& & & & & & & & & & & & StdUserControl.CurrentUser =& & & & & & & & & & & & #endregion& & & & & & & & & & & & Member_level_infoIBLL ibllmemberlevel = new Member_level_infoBLL();& & & & & & & & & & & & StringBuilder strmemlevel = new StringBuilder();& & & & & & & & & & & & strmemlevel.Append(" and levelId='" + memberinfo.levelId.ToString() + "'");& & & & & & & & & & & & string strlevelname = ibllmemberlevel.GetEntityWhere(strmemlevel).levelName.ToString();& & & & & & & & & & & & StringBuilder strmember = new StringBuilder();& & & & & & & & & & & & strmember.Append("&div class='task'&&div class='img'&&img width='75' height='60' src='http://ayue05./blog/images/pic02.jpg'&&/div&&div class='right'&&p&&span class='red'&" + memberinfo.memberName.ToString() + "&/span&(" + (memberinfo.isAduit.ToString() == "1" ? "已激活" : "未激活") + ")&/p&&p&上次登录时间:&/p&&p&" + memberinfo.lastLoginDate.ToString().Substring(0, memberinfo.lastLoginDate.ToString().IndexOf(" ")) + "&/p&&/div&&/div&");& & & & & & & & & & & & strmember.Append("&p&账户余额:&span class='red'&¥" + memberinfo.Balance.ToString() + "&/span&&a class='blue' href='http://ayue05./blog/#'&账户设置&/a&&/p&");& & & & & & & & & & & & strmember.Append("&p&积分:&span class='red'&" + memberinfo.Integration.ToString() + "&/span&&a class=' blue' href='http://ayue05./blog/#'&兑换&/a&&/p&");& & & & & & & & & & & & strmember.Append("&p&发布点个数:&span class='red'&97.195&/span&个&/p&");& & & & & & & & & & & & strmember.Append("&p&收藏点个数:&span class='red'&8&/span&个&/p&");& & & & & & & & & & & & strmember.Append("&p&VIP:" + (strlevelname == "VIP会员" ? "是" : "否") + "&/p&");& & & & & & & & & & & & strmember.Append("&p&信托卡:单钻信托卡&/p&");& & & & & & & & & & & & strmember.Append("&p&商保:否&/p&");& & & & & & & & & & & & strmember.Append("&p class='task_bom'&&a href='http://ayue05./blog/#'&发布任务&/a&&/p&");& & & & & & & & & & & & strmember.Append("");& & & & & & & & & & & & //result = strmember.ToString();& & & & & & & & & & & & Session["index_memberinfoArea"] = strmember.ToString();& & & & & & & & & & & & result = "登陆成功";& & & & & & & & & & }& & & & & & & & & & else& & & & & & & & & & {& & & & & & & & & & & & Session["index_memberinfoArea"] = "";& & & & & & & & & & & & result = "登陆失败";& & & & & & & & & & } & & & & & & & & & && & & & & & & & }& & & & & & & & else& & & & & & & & {& & & & & & & & & & result = "验证码错误";& & & & & & & & }& & & & & & }& & & & & & else& & & & & & { & & & & & & & && & & & & & & & result= "请输入完整";& & & & & & }& & & & & & Response.Write(result);& & & & & & Response.End();& & & & & && & & & }& & & & #endregion& & & & #region 退出登陆& & & & [WebMethod]& & & & public static string LoginOut()& & & & {& & & & & & HttpContext.Current.Session.Clear(); & & & & & && & & & & & return "退出成功";& & & & } & & & && & & & #endregion& & & & #region 我要接手,是否已登陆,是否自己的任务& & & & //[WebMethod]& & & & public string spTaskOver(string memberuname)& & & & {& & & & & & //如果用户有登陆,且非自己发的任务。则可接手 & & & &&& & & & & & //if (HttpContext.Current.Session["index_memberinfo"] != null)& & & & & & //{& & & & & & & &&& & & & & & //}& & & & & & //else& & & & & & //{& & & & & & & &&& & & & & & //}& & & & & & //string result = "成功";& & & & & & //& & & & & & Response.Write(memberuname);& & & & & & Response.End();& & & & & && & & & }& & & & #endregion& & }}&$(function () {&&&&&&&&&&& //获取手机验证码&&&&&&&&&&& $("#GetPhoneCode").click(function () {&&&&&&&&&&&&&&& $.ajax({&&&&&&&&&&&&&&&&&&& url: '/Home/Member_Register.ashx',&&&&&&&&&&&&&&&&&&& type: 'post',&&&&&&&&&&&&&&&&&&& data: "action=GetPhoneCode&phoneValues=" + $('#phoneValues').val(),&&&&&&&&&&&&&&&&&&& dataType: 'json',&&&&&&&&&&&&&&&&&&& success: function (d) {&&&&&&&&&&&&&&&&&&&&&&& if (d.isSucceed == true) {&&&&&&&&&&&&&&&&&&&&&&&&&&& $("#GetPhoneCode").attr({ "disabled": "disabled" });//禁用获取手机验证码按钮&&&&&&&&&&&&&&&&&&&&&&&&&&& $("#GetPhoneCode").addClass("BtnDisabledCss");&&&&&&&&&&&&&&&&&&&&&&&&&&& ForbiddenGetPhoneCodeBtn(60);//禁用获取手机验证码按钮60秒&&&&&&&&&&&&&&&&&&&&&&&&&&& $('#divID').hLoading({ type: 'success', timeout: 5000, msg: d.info });&&&&&&&&&&&&&&&&&&&&&&& } if (d.isSucceed == false) {&&&&&&&&&&&&&&&&&&&&&&&&&&& $('#divID').hLoading({ type: 'fail', timeout: 5000, msg: d.info });&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&& });&&&&&&&&&&& });&&&&&&& });
阅读(2953)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'jQuery AJAX实现调用页面后台方法。调用ashx方法',
blogAbstract:'1.新建demo.aspx页面。2.首先在该页面的后台文件demos.aspx.cs中添加引用。using System.Web.S3.无参数的方法调用.大家注意了,这个版本不能低于.net framework 2.0。2.0已下不支持的。后台代码:[WebMethod] & &&public static string SayHello() & &&{ & &&& & &return \"Hello Ajax!\"; & &&',
blogTag:'异步调用,ajax,ashx',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:1,
publishTime:2,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'坦诚.直率.开朗.认真',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 jquery获取ajax返回值 的文章

 

随机推荐