[英]Ajax and MVC 4 ( post request)
我想向控制器發送一個簡單的字符串(即xml)。 我不知道為什么Visual Studio中的斷點沒有命中。
這是jQuery代碼:
$.ajax({
type: "POST",
url: "BasicWizard/show",
data: "xml="+xmlResult,
success: function (data) {
console.log("Oh yeah !");
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
這是我在控制器中的方法:
[HttpPost]
public ActionResult show(string xml)
{
try
{
ViewBag.xml = xml;
return PartialView("showXML");
}
catch (Exception)
{
return Content("error");
}
}
我在控制台中只有500錯誤。
嘗試這個 :-
data: "{'xml':'" + xmlResult+ "'}",
帖子數據格式不正確。 嘗試傳入encodeURIComponent(xmlResult)
而不是xmlResult
。 這將轉義=
和其他在帖子值中無法正常使用的字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.