GET 请求控制器 返回绑定后HTML
//$.get("/Home/index/" + $("#S_BookName").val(), function (data) { //MVC控制器返回View(Model) 是没有绑定后的html页面 // console.log(data); // //var Number1 = data.indexOf("<table");//返回索引 // //var Number2 = data.indexOf("</table>");//第二个索引 //返回索引有误 // //console.log("1*" + Number1); // //console.log("2*" + Number2); // //console.log(data.substring(Number1, Number2 - Number1)); // //$("#tab1").replaceWith("HTML代码"); //}); //执行get请求
public ActionResult Index(string U,string P) //get/post都能接收 等于 //Request["U"] 只能接收u和p { ViewBag.U = U; //Request["U"];//GET/POST都能获取 ViewBag.P = P; //Request.Form["P"];//不能获取GET只能获取POST return View(); }
public ActionResult Index(string U,string P) //get/post都能接收 等于 //Request["U"] 既能接收U和P 还能接收x和y { ViewBag.U = Request["x"];//GET/POST都能获取 ViewBag.P = Request.Form["y"];//不能获取GET只能获取POST return View(); }
<script> function ppost() { console.log("ppost"); $.ajax({ type: "post", url: "index", data:{U:'1234',P:'000'}, async: false,//异步和同步都不刷新页面 success: function (data) { console.log(data); } }); } function gget() { console.log("gget"); $.ajax({ type: "GET", url: "index", data: { U: '1234', P: '000' },//等同于data:"U=1234&p=000" async: false, success: function (data) { console.log(data); } }); } </script>