返回string
var A="...";
var B="...";
$.ajax({
type: "POST",
url: "/Controller/Action",
data: { "A": A,"B": B},
success: function (result) {
layer.alert(result, '操作结果');
}
});
public ActionResult Action(string A,string B)
{
ABManager manager =new ABManager();
string result =manager.DoSomething(A, B);
return Json(result, JsonRequestBehavior.AllowGet);
}
返回匿名对象
<div><button onclick="GetResult()">点击</button></div>
<script>
function GetResult() {
var A = "A";
var B = "B";
$.ajax({
type: "POST",
url: "/AboutC/ReturnObjectFromCAjax",
data: { "A": A, "B": B },
success: function (result) {
if (result.Success == true) {
layer.alert('操作成功,结果为' + result.A + "," + result.B);
}
else {
layer.msg('操作失败,请稍后重试...');
}
}
});
}
</script>
public ActionResult ReturnObjectFromCAjax(string A,string B)
{
return Json(new
{
A = A + "_ok",
B = B + "_ok",
Success=true
});
}