码迷,mamicode.com
首页 > Web开发 > 详细

ajax调用后台webservice返回JSON字符

时间:2015-07-10 13:23:13      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

 

后台代码:

[WebMethod]
public static string LoginTest(string userCode, string password)
{
UserManageCenterService service = new UserManageCenterService();
string msg = string.Empty;
service.AuthenticateUser(userCode, password, 10000, out msg);

if (msg == "验证成功")
{
string callBackURL = System.Configuration.ConfigurationManager.AppSettings["CallBackURL"].ToString();
msg = "{\"sign\":\"authenticated\",\"url\":" + ‘\"‘ + callBackURL + ‘\"‘ + "}";
return msg;
}
return msg;
}

前台代码:

$(document).ready(function () {
$("#btnlogin").click(function () {
if (CustomLogin() != false) {
$.ajax(
{
type: "POST",
contentType: "application/json",
url: "Login.aspx/LoginTest",
data: "{‘userCode‘: ‘" + $("#txtUserName").val() + "‘, ‘password‘:‘" + $("#txtPassword").val() + "‘}",
dataType: "json",
success: function (msg) {
ajaxobj = eval("(" + msg.d + ")");
if (ajaxobj.sign == "authenticated") {
window.location.href = ajaxobj.url;
}
else {
alert(msg.d);
}
}
});
}
});
});

ajax调用后台webservice返回JSON字符

标签:

原文地址:http://www.cnblogs.com/star2012/p/4635274.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!