|
楼主 |
发表于 2015-6-24 13:18:25
|
显示全部楼层
function getitem() {
var item = {
action: "getid",
Name: 'sufei',
url: "s1.ashx?jsoncallback=?"
};
return item;
}
$(function () {
$("#Button1").click(function () {
var item = getitem();
try {
$.getJSON(item.url, item, function (msg) {
if (msg) {
var id = msg.id;
alert(id);
}
});
} catch (e) {
alert(e);
}
});
});
--------------------------------------------------------------------
/// </summary>
public class s1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// do action
if (context.Request["action"] != null)
{
string action = context.Request["action"].ToString().Trim();
string jsoncallback = context.Request["jsoncallback"].ToString();
string result = string.Empty;
if (action == "getid")
{
string name = context.Request["Name"].ToString();
if (name == "sufei")
{
result = "11001";
}
}
context.Response.Clear();
context.Response.Write(jsoncallback + "({id:'" + result + "'})");
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
//以上是您原来的代码
----------------------------------------------------------------------------------------------------------------------------------------------------------------以下是我原来的代码
// var data = $('#txtBizName').val() + "$" + $('#txtContactperson').val() + "$" + $('#txtPhone').val() + "$" + $('#txtRemark').val();
// $.ajax({
// type: "post", //要用post方式
// url: "bizcooperation.aspx/NewCooperation", //方法所在页面和方法名
// contentType: "application/json; charset=gb2312",
// dataType: "json",
// data: "{'CooInfo':'" + data + "'}",
// success: function (data) {
// alert(data.d); //返回的数据用data.d获取内容
// },
// error: function (err) {
// alert(err);
// }
// });
---------------------------------------------------后台
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
[WebMethod]
public static string NewCooperation(string CooInfo)
{
Model.rc_model.Cooperation Coo = new Model.rc_model.Cooperation();
CooManage Cm = new CooManage();
string[] Cinfo = CooInfo.Split(new char[] { '$' });
Coo.CooID = Utils.GetGuid();
Coo.Enterprise = Cinfo[0].ToString();
Coo.ContactName = Cinfo[1].ToString();
Coo.Phone = Cinfo[2].ToString();
Coo.CooState = false;
Coo.CreateTime = DateTime.Now;
Coo.BizRemark = Cinfo[3].ToString();
int Result = Cm.AddCoo(Coo);
return "{'result':'" + Result.ToString() + "'}";
}
//谢谢
|
|