2014-01-11 23 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); 
    }