我对 ajax 和 JSON 的了解有限,但我知道在 ajax 调用中使用 JSON.stringify 有时会很有用。我下面的 ajax 调用工作正常,而下面的 stringify 方法则不起作用。我想知道我是否正确使用 .stringify,如果没有,我什么时候应该在 ajax 中使用 JSON.stringify(如果有的话)。我将 MVS 与模型、视图和控制器一起使用。
这就是我通常进行 ajax 调用的方式,以及构建 url 部分的方式。
function AddEquipment(id, name, type, description, email) {
$.ajax({
url: '@Url.Action("AddEquipment", "Home")' + '/?id=' + id +
"&name=" + name + "&type=" + type + "&description=" +
description + "&email=" + email,
type: "GET",
cache: false,
datatype: "JSON",
success: function(result) {
//do stuff
}
});
}
Run Code Online (Sandbox Code Playgroud)
下面我尝试使用 JSON.stringify 而不是手动构建整个 url,但它不起作用。
function AddEquipment(id, name, type, description, email) { …Run Code Online (Sandbox Code Playgroud)