(1)js代碼:
var data = {
a: "1",
b: "b"
}
$.ajax({
type: "get",
url: '../Dic/TestA',//也可TestA2
data:data ,
dataType: "JSON",
success: function (result) {
}
});
$.ajax({
type: "POST",
url: '../Dic/TestB',//也可TestB2
data: data,
dataType: "JSON",
success: function (result) {
}
});
$.ajax({
type: "POST",
url: '../Dic/TestB3',
data: JSON.stringify(data),
dataType: "JSON",
success: function (result) {
}
});
(2)後臺c#代碼:
public class TestController : ControllerCore
{
public class A {
public string a { get; set; }
public string b { get; set; }
}
[HttpGet]
public ActionResult TestA(string a,string b)
{
return null;
}
[HttpGet]
public ActionResult TestA2(A data)
{
return null;
}
[HttpPost]
public ActionResult TestB(string a, string b)
{
return null;
}
[HttpPost]
public ActionResult TestB2(A data)
{
return null;
}
[HttpPost]
public ActionResult TestB3()
{
var requestFormData = Request.Form;
string bbb = System.Web.HttpUtility.UrlDecode(requestFormData.ToString(), System.Text.Encoding.GetEncoding("GB2312"));
return null;
}
}