我已經在我看來,下面的代碼:的JavaScript在C#MVC4不點火
<script type="text/javascript">
function OnCancelClick(e)
{
var jobId = e;
var flag = confirm('You are about to cancel job : ' + jobId + '. Are you sure you want to cancel this job?');
if (flag) {
$.ajax({
url: '/job/CancelJob',
type: 'POST',
data: { jobId: jobId },
dataType: 'html',
success: function (result) { alert('Job ' + jobId + ' was cancelled.'); document.location = "@Url.Action("Index", "Job")"; },
error: function() { alert('Something went wrong. Check the log for more information.'); }
});
}
return false;
}
</script>
在我看來,我也有:
<input type="submit" id="cancelButton" value="Cancel" onclick="javascript: return OnCancelClick(@Model.Id);" />
在我的控制,我有:
[HttpPost]
public ActionResult CancelJob(int jobId)
{
try
{
logger.LogInfo(string.Format("<start> Cancel-button clicked for job : {0}", jobId), jobId);
JobCommandService.ChangeStatus(jobId, 6);
logger.LogInfo(string.Format("<end> Cancel-button clicked for job : {0}", jobId), jobId);
return RedirectToAction("Index", "Job");
}
catch (Exception ex)
{
logger.LogError(ex.Message, ex, jobId);
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return Json(new { Success = false, Message = ex.Message });
}
}
當我在我的VS2012中運行它時,它工作得很好。 當我將它部署到服務器時,我收到錯誤信息。 在我的日誌記錄中沒有被點擊的按鈕的軌跡。
確保所有腳本都正確地包含在生產服務器上。除此之外,你會得到什麼錯誤信息? – Robert
我沒有收到任何消息。我得到的唯一信息是「'出錯了,請查看日誌以獲取更多信息。」但是我的日誌裏沒有任何東西。甚至沒有點擊按鈕的痕跡。 –
當我查看我的頁面源時,腳本就在那裏。所以這應該沒問題。 –