【发布时间】:2015-03-03 02:26:03
【问题描述】:
这不起作用,服务器上的值为null。
JavaScript:
$.ajax({
url: '/PlayZone/GetCards',
type: "GET",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({ 'what': what, 'by': by, 'jump': jump }),
});
C#:
[HttpGet]
public ActionResult GetCards(string what ,string by, string jump)
{
...
}
这工作正常,但我需要 GET ajax 工作才能喜欢这篇文章。 Javascript:
$.ajax({
url: '/PlayZone/GetCards',
type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({ 'what': what, 'by': by, 'jump': jump }),
});
C#
[HttpPost]
public ActionResult GetCards(string what ,string by, string jump)
{
...
}
【问题讨论】:
-
任何 .success 或 .fail ???
-
您是否尝试过使用一个对象而不是 3 个单独的参数?
-
不要字符串化
data。只需传递对象 -data: { 'what': what, 'by': by, 'jump': jump }, -
我不知道这个问题,但我敢肯定,使用
POST来实际得到一些东西是个坏主意......也许这甚至是答案的一部分...... . -
GET请求的content-type不能设置,没有请求体来描述内容。
标签: javascript ajax asp.net-mvc-5