之前写的Ajax 本来没有问题,过久了不写老是报错
程序这个东西 一点点不对就报错
有的是收不到值
有的是 格式不对
前端代码
@{
ViewBag.Title = “Index”;
}
后端代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace test.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult getsum(string id)
{
try
{
// string iid = Request.Params["id"];
int idd = int.Parse(id);
int xxx = idd + 10000;
return Json(xxx, JsonRequestBehavior.AllowGet);
}
catch {
var xx = "操作失败";
return Json(xx, JsonRequestBehavior.AllowGet);
}
}
}
}

本文探讨了在长时间未维护后,原有的Ajax与MVC交互代码出现的问题及解决策略。详细分析了从前端到后端可能出现的错误类型,如收不到值、格式错误等,并提供了具体的代码实例。
1001

被折叠的 条评论
为什么被折叠?



