这是我的职责
function reqQuoteFile(_url) {
$.ajax({
type: "GET",
url: _url,
dataType: "json",
success: function (data) {
if(data["itemsNotSupportedWarning"] != '')
{
alert(data["itemsNotSupportedWarning"]);
//more code...
}
}
});
}
它称这个动作
public ActionResult ExportQuote(string projectNumber)
{
//more code here...
return Json(new
{ quoteFileName = _quoteFileName,
itemsNotSupportedWarning = _itemsNotSupportedWarning
});
}
_quoteFileName和_itemsNotSupportedWarning是字符串。
当我在调试模式下运行代码时,ajax正在调用该动作。但是,执行该操作后,不会显示警报弹出窗口。
感谢您的帮助。
好吧,您正在正确返回匿名类型。但是,您需要添加JsonRequestBehavior.AllowGet
例如
public ActionResult ExportQuote(string projectNumber)
{
//more code here...
return Json(new
{ quoteFileName = _quoteFileName,
itemsNotSupportedWarning = _itemsNotSupportedWarning
}, JsonRequestBehavior.AllowGet);
}
另外,这不是必需的,但是您可以更改data["itemsNotSupportedWarning"]
为data.itemsNotSupportedWarning
以访问json属性:
//change to data.itemsNotSupportedWarning
if (data.itemsNotSupportedWarning != '') {
alert(data.itemsNotSupportedWarning);
//more code...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句