62,243
社区成员




页面JS代码如下:
方法一:
$.getJSON(
"http://ip地址/chatService/chatService.asmx/userLogin?jsoncallback=?",
{userId:"'"+$("#userId").val()+"'", serverId:"'"+$("#serverId").val()+"'", date:"'"+new Date()+"'"},
function(json)
{
if(json.length > 0)
{
alert(json); }
}
);
方法二:
$.ajax({
async: false,
type: "POST",
contentType:"application/json;utf-8",
url: "http://ip地址/chatService/chatService.asmx/userLogin?callback=?",
data: "{userId:'"+$("#userId").val()+"', serverId:'"+$("#serverId").val()+"', date:'"+ new Date() +"'}",
datatype:"json",
success: function(json){
if(json != "")
{
alert(json);
}
}
});
web service方法
已经包含了[System.Web.Script.Services.ScriptService]
[WebMethod]
public void userLogin(string userId, string serverId, string date)
{
DBManager db = new DBManager("COM");
SqlParameter[] p = new SqlParameter[4];
p[0] = new SqlParameter("@userId", SqlDbType.Int, 0);
p[0].Direction = ParameterDirection.Input;
p[0].Value = userId;
p[1] = new SqlParameter("@serverId", SqlDbType.Int, 0);
p[1].Direction = ParameterDirection.Input;
p[1].Value = serverId;
p[2] = new SqlParameter("@date", SqlDbType.DateTime, 0);
p[2].Direction = ParameterDirection.Input;
p[2].Value = date;
p[3] = new SqlParameter("@returns", SqlDbType.Int, 0);
p[3].Direction = ParameterDirection.ReturnValue;
int sysId = db.ExeProc("ap_webUserLog", p);
string callback = HttpContext.Current.Request["jsoncallback"];
string retV = "";
retV += "({state:" + sysId + ", msg:'成功建立连接'})";
HttpResponse response = HttpContext.Current.Response;
response.Write(callback + retV);
response.End();
}
{userId:"1", serverId:"10", date:"2010-07-13 17:55:55"},
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>