<script type="text/javascript">
var telphone = { type: "getphone", "num": dianhua, "typestr": index };
$.ajax({
type: 'POST',
url: '/webService/GetMobile.ashx',
data: telphone,
dataType: 'text',
success: (function (data) {
if (data == "ok") {
alert("提交成功!");
$(".storesContents_Box1:eq(" + index + ") .txtmobile").val("");
$(".storesContents_Box1:eq(" + index + ") .txtmobile").focus();
}
else {
alert("提交失败!");
}
})
</script>
后台 GetMobile.ashx'
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
var type = context.Request.Params["type"];
var telphoneNumber = context.Request.Params["num"];
if (!string.IsNullOrEmpty(telphoneNumber))
{
using(EF db = new EF())
{
Telphone xTelphone = new Telphone();
xTelphone.Telphone = telphoneNumber;
db.Telphone.AddObject(xTelphone);
db.SaveChanges();
}
}
switch (type)
{
case "getphone":
{
context.Response.Write("ok");
break;
}
}
}
public bool IsReusable
{
get
{
return false;
}
}