ajax请求异步刷新页面=把需要异步刷新的页面单独写成一个.cshtml进行操作$.ajax({}); -------ajax方法。type: ------- 类型,此处为“POST” 还有 "GET"类型。必须全部大写。View和Controller请求方式保持一致。url: ------- 调用的Action 书写格式 /controller/actioncontroller为文件夹的名字,即不加后缀"controller"data: ------- 参数,没有可以不写data这一项success: function (sesponseTest) {} ------- 回调函数,就是当我的Action 执行完后,执行的方法。sesponseTest为Action返回的内容。$("#txt1").val(sesponseTest); ------- 把返回的字符串赋值给文本框。
(1)Ajax可以是POST/GET(2)传参方式第一种“key”:value, “key”:valuedata:{”index”:index,”name”:name….}第二种key:value, key:valuedata:{index:index,name:name….}第三种“key=”+value+”&&”+data:”index=”+index+”&&”+”name=”+name…(3)取值a.方法的参数列表
Public ActionResult GetData(int index,string name){…}b.Request[“name”]
public ActionResult GetData{int index=Request[“Index”];….}c.类对象
public ActionResult AddNews(userModel user) { string a=user.text1; string b=user.text2; }d.从MVC封装的FormCollection容器中读取
public ActionResult AddNews(FormCollection form) { string a=form["text1"]; string b=form["text2"]; }(4)其他 get方法window.open("/Js/PostWithParameters?number1="+ 1+ "&number2=" +2);
转载于:https://www.cnblogs.com/Lulus/p/7873831.html
相关资源:Jquery操作Ajax方法小结