2014-01-11 24 views
0

我有这个功能阿贾克斯:连接JQuery的阿贾克斯发挥到控制器功能

$.ajax({ 
     url: '/Notification/Send', 
     type: "POST", 
     cache: false, 
     data: { 
      usr: userId, 
      rcv: receiverId, 
      txt: text 
     }, 
     success: function (data) { 
      //some code 
     } 
    }); 

这个功能控制器:

[HttpPost] 
public string Send(string usr, string rcv, string txt) 
    { 


     return txt; 
    } 

所以不执行“成功”块.. 。 这段代码有什么问题?

+0

您是否收到任何错误? – Mutant

+0

是啊............ – godot

+0

没有错误,但不起作用...这个ajax函数在调用按下按钮时调用的一个JavaScript函数中......并且在按下后不会改变任何东西 – godot

回答

0

尝试

[HttpPost] 
public ActionResult Send(string usr, string rcv, string txt) 
    { 


     return Json(txt); 
    } 

如果是GET请求,那么你必须要做到这一点

return Json(txt, JsonRequestBehavior.AllowGet); 
0

试图改变你的数据在你的Ajax功能是这样的:

data: JSON.stringify({ 
     usr: userId, 
     rcv: receiverId, 
     txt: text 
    }), 

并尝试指定content typedataType明确:

dataType: "json", 
contentType: "application/json; charset=utf-8", 
+0

感谢您的回答,但在甚至不工作:( – godot

+0

在数据中,当我只写一个参数,它的工作... – godot

+0

再次检查.... –

0

尝试下面的代码snippet.Change方法的返回类型

[HttpPost] 
public ActionResult Send(string usr, string rcv, string txt) 
    { 


     return Content(txt); 
    }