使用字符串回复以在 JSON 成功时发挥作用
Reply with string to function on JSON success
我想在 JSON 返回时向 JS 函数发送一条消息。正如您在下面看到的,我试图将消息插入 JSON 回复中,但我得到了[object][object]
而不是消息。如何阅读消息?
这是我的代码:
控制器:
public ActionResult UpdateCategory(Category category)
{
// do something.
// I want to send this message back to the function:
var message = "some message to reply."
// I was trying this:
// return Json(new { success = true, message = message }, JsonRequestBehavior.AllowGet);
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
脚本
$.ajax({
type: "POST",
url: "/UpdateCategory",
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (message) {
alert(message); // I would like to show here the message.
},
error: function () {
$('.overlay').hide();
alert("error");
}
});
把这一行放回去:
return Json(new { success = true, message = message }, JsonRequestBehavior.AllowGet);
然后更改
alert(message);
自
alert (message.message)
相关文章:
- I'我试图在文本区域中进行特定的输入,调用特定的javascript函数,但没有成功;不起作用
- Ajax成功上的Phonegap WebSQL事务不起作用
- 按钮在第一次成功的 ajax 数据加载后不起作用
- 构建Ajax调用数组时,JQueryAjax成功回调不起作用
- 多个AJAX调用调用相同的成功函数不起作用
- 谷歌登录成功功能在我阻止第三方cookie时没有任何作用
- 成功提交 Web 表单后,Javascript 重置功能将不起作用
- JQuery .ajax() 函数调用不起作用,但成功方法运行
- 为什么成功:函数()不起作用
- AJAX 成功函数不起作用
- AJAX 中的成功或错误回调不起作用
- 骨干.js:Save的成功功能根本不起作用
- Ajax 成功函数第二次不起作用
- 使用字符串回复以在 JSON 成功时发挥作用
- jQuery AJAX函数成功不起作用
- Ajax 成功事件多错误不起作用
- $(this).find(“.text”)和(“.loading”)在AJAX成功函数内部不起作用
- $.ajax成功处理程序don'中的jQuery方法;不起作用
- 在ajax成功之后,Javascript;不起作用
- Ajax成功函数在jquery mobile中不起作用