第一種:javascript
//請求數據 var paras = { taskGuidNo: taskGuidNo, taskCycle: taskCycle, userId: userId }//過濾條件 $.ajaxSettings.async = false; //非異步 $.get('@Url.Action("GetQuery", "TaskManager")', paras, function(result) { }, 'json' );
public class TaskManagerController : BaseController { public ActionResult GetQuery(string taskGuidNo,int taskCycle,string userId) { var result = ""; return Json(result, JsonRequestBehavior.AllowGet); } }
第二種:java
var taskReportInfo = { GuidNo: taskGuid, TaskCycle: taskCycle, Content: reportContent, Img: imgStr }; $.ajax({ url: "AjaxTaskReportSubmit", data: taskReportInfo, type: "POST", success: function (result) { if (result.Success) { window.location.href = "MyTaskList"; } } });
// 提交表單數據到後臺處理
$.ajax({
type: "post",
data: studentInfo,
contentType: "application/json",
url: "/Home/Submit",
beforeSend: function () {
// 禁用按鈕防止重複提交
$("#submit").attr({ disabled: "disabled" });
},
success: function (data) {
if (data == "Success") {
//清空輸入框
clearBox();
}
},
complete: function () {
$("#submit").removeAttr("disabled");
},
error: function (data) {
console.info("error: " + data.responseText);
}
});ajax
public class TaskManagerController : BaseController { [HttpPost] public ActionResult AjaxTaskReportSubmit(TaskReportSubmitViewModel taskReportInfo) { var result = new ResultModel(); try { result = "" } catch (Exception ex) { result.GetException(ex); } return Json(result); } }
public class TaskReportSubmitViewModel { public string GuidNo { get; set; } /// <summary> /// 任務階段 /// </summary> public int TaskCycle { get; set; } /// <summary> /// 彙報內容 /// </summary> public string Content { get; set; } /// <summary> /// 圖片 /// </summary> public string Img { get; set; } }