62,025
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JqueryCSMethodForm.aspx.cs"
Inherits="JqueryCSMethodForm" %>
<!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">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("input[type='button'][value='GetDate']").click(function() {
$.ajax({
type: "post",
url: "JqueryCSMethodForm.aspx/GetNowDate",
datatype: "text",
contentType: "application/json; charset=utf-8",
success: function(data) {
$("input#showTime").val(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="GetDate" />
<input type="text" id="showTime" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
public partial class JqueryCSMethodForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static String GetNowDate()
{
return "[{\"nowtime\":\"" + DateTime.Now.ToShortDateString() + "\"}]";
}
}
var datainfo={mobileSp:'1',unicomSp:'1'}
$.ajax({
type : 'POST',
url:'../aa.aspx',
dataType:'json',
data : datainfo,
success: function(data){
try{
if(data.success) {
Ext.Msg.alert('提示',"信息已经提交成功");
}else{
alert(data.error);
}
}catch(e){
alert('发生异常错误!');
}
}
});
protected void Page_Load(object sender, EventArgs e) {
SaveData();
}
private void SaveData() {
string mobileSp = Request.Form["mobileSp"];
string unicomSp = Request.Form["unicomSp"];
if (mobileSp != null) {
//此处进行数据库处理
count=0;//count为数据库处理回来的值
if (count == 0) {
Response.Write("{success:true,error:'信息保存成功'}");
} else if (count == -1) {
Response.Write("{success:false,error:'信息提交失败,原因:" + ApplicationLog.ErrorDescription.Replace("\"", "\\\"").Replace("\r", "\\r").Replace("\n", "\\n") + "'}");
} else if (count == -2) {
Response.Write("{success:false,error:'信息提交失败,原因:" + error + "'}");
} else {
Response.Write("{success:false,error:'信息提交部分成功,失败号码:" + error + "'}");
}
} else {
Response.Write("{success:false,error:'信息不完整'}");
}
}