我使用的是上述方法,它与 URL 中的一个参数配合使用效果很好。
例如Students/getstud/1
应用了 Controller / Action /参数格式。
现在我在 Students Controller 中有一个 Action ,它接受两个参数并返回一个 JSON 对象。
那么如何使用 post 方法通过 $.getJSON()
发布数据?
也可以采用类似的方法。
重点是使用 AJAX 调用 Controller 的操作。
最佳答案
$.getJSON() 方法执行 HTTP GET 而不是 POST。您需要使用 $.post()
$.post(url, dataToBeSent, function(data, textStatus) {
//data contains the JSON object
//textStatus contains the status: success, error, etc
}, "json");
在该调用中,dataToBeSent
可以是您想要的任何内容,尽管如果发送的是 html 表单的内容,您可以使用 serialize方法从您的表单创建 POST 数据。
var dataToBeSent = $("form").serialize();
关于jquery - 如何使用getJSON,用post方式发送数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/751218/