ajax 返回数据[Object Object]
问 这里面到底出现什么问题,
前台
html>
function Send() {
var loginUserId = $("#").val();
$.ajax({
//提交方式
type: "Post",
//路径
url: "Code/ValidCode.ashx?Method=Send",
data: {
Loginid: loginUserId,
d: new Date()
},
dataType: "text",
//返回数据-需要返回JSON格式的数据(Jquery 1.4版本+以后要求返回数据格式是严格的JSON格式的数据)
success: function (json) {
alert(json);
//if (json.MessageText == 1) {
// alert("发送邮件成功.");
//} else if (json.MessageText == 0) {
// alert("Send mail success.");
//}
},
error: function (e) {
alert(e);
}
});
}
验证 | 发送验证码 |
ASHX文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using Entity;
using Newtonsoft.Json;
namespace WebCrm.Code
{
///
/// ValidCode 的摘要说明
///
public class ValidCode : IHttpHandler
{
HttpContext _httpContext;
HttpCookie _cookie;
public void ProcessRequest(HttpContext context)
{
//不让浏览器缓存
context.Response.ContentType = "text/plain";
//context.Response.Buffer = true;
//context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
//context.Response.AddHeader("pragma", "no-cache");
//context.Response.AddHeader("cache-control", "");
//context.Response.CacheControl = "no-cache";
_httpContext = context;
string method = _httpContext.Request["Method"].ToString();
MethodInfo methodInfo = this.GetType().GetMethod(method);
methodInfo.Invoke(this, null);
}
///
/// 发送验证码
///
public void Send()
{
//Json数据返回格式
Entity.ReturnsData returnsData = new Entity.ReturnsData();
//获取对象值
string login = _httpContext.Request["Loginid"];
//获取当前用户缓存
Entity.LoginInfo loginInfo = BLL.CacheBll.GetCache(login) as Entity.LoginInfo;
if (loginInfo != null)
{
int d = 0;
//判断当前是否存在Cookies
if (_httpContext.Request.Cookies["ValidInfo"] == null)
{
Random rand = new Random();
d = rand.Next(100001, 999999);
//Session["ValidCode"] = d;
TimeSpan ts = new TimeSpan(0, 0, 15, 00);//cookie有效作用时间
_cookie = new HttpCookie("ValidInfo");
_cookie.Expires = DateTime.Now.Add(ts);
_cookie.Values.Add("ValidCode", d.ToString());
_httpContext.Response.AppendCookie(_cookie);
BLL.EmailHelper.SendMail(d, loginInfo.DefaultMail, loginInfo.IsEnglish);
returnsData.MessageText = loginInfo.IsEnglish ? 0 : 1;
_httpContext.Response.Write(returnsData.MessageText);
_httpContext.Response.End();
}
}
}
///
/// 验证
///
public void Validation()
{
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
------解决思路----------------------
json.ResponseText 试试
------解决思路----------------------
换一个JQ版本。