MVC前端JS如何传值给后端int id的值,有人知道吗?
MVC前端JS如何传值给后端int id的值,有人知道吗?
MVC前端JS如何传值给后端改变int id的值,有人知道吗?
后端控制器
public static int id = 1;
访问的时候通过参数传递,如果页面内需要多次改变,建议使用异步加载去处理
传值给后端,意味着你需要提交数据,可以通过POST进行提交,后端写接收的方法即可。
能给段代码吗?谢谢!
前端
$.ajax(
{
url: '数据请求地址', // 请求地址, 就是你的控制器, 如 test.com/home/index/index
type: 'get', // 请求方式
dataType: 'json', // 返回数据的格式, 通常为JSON
data: { 'id': 10 }, // 需要传送的参数
success: function (result) {
alert(result); // 请求成功后的回调函数, result 为响应内容
},
error: function () {
alert('Send Request Fail..'); // 请求失败时的回调函数
}
}
后端
public static int id= -1;
好象不行啊