对于 ajax GET,值为空
Values are null for ajax GET
这是行不通的,值在服务器上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)
{
...
}
试试这个
$.ajax({
url: '/PlayZone/GetCards',
dataType: "json",
type: "POST",
data: { what: what, by: by, jump: jump },
success: function (response) {
alert("success");
}
});
只需在 java 脚本中传递如下值
data: {'what': what, 'by': by,'jump': jump }
当使用 Get 作为类型时,将数据传递到服务器的唯一方法是通过 url。
您可以通过执行类似操作来侥幸逃脱:
$.get("/PlayZone/GetCards", {what: what, by: by, jump: jump}).done(function(result) {});
Jquery 会将 javascript 对象更改为查询字符串参数以传递给您的操作。
另一种方法是生成一个包含虚拟数据的查询字符串参数的 URL,然后在该字符串上使用替换来添加值。
就个人而言,我会选择$.get解决方案
相关文章:
- jQuery Ajax GET请求工作不正常
- 如何在nightwatch.js中发送ajax get请求
- 如何在调用下一个请求之前完成第一个Ajax Get请求
- 使用Ajax Get方法将数据显示到特定元素中
- 如果我对一个文件发出ajax GET请求,我会得到什么以及如何将其添加到页面中
- 成功函数未在 ajax GET 方法中调用
- Javascript 变量通过 AJAX(GET 方法)到 PHP
- Ajax GET 请求的 URL 失败,但 hurl.it 相同 URL 的 GET 请求有效.什么给
- 如何显示Ajax Get-Method中的数据
- ajax get-json函数没有'不起作用
- Rails4:是否可以将Ajax.get请求发送到相同的当前页面控制器
- AJAX Get不是't工作
- 错误:使用ajax.get时,元素后应为]标记
- 如何从ajax get请求的回调函数中编辑javascript变量的值
- 如何根据ajax get请求的成功/失败在适当的范围内更改javascript变量
- 如何执行Ajax GET请求以从rails获取数据并将其传递给javascript(谷歌地图)
- Ajax get jsonp给出错误代码500“;请求被阻止”;来自MVC应用程序
- 我的Ajax GET是't工作
- Ajax get 方法不起作用
- laravel ajax get request on orderBy => internal server er