无论使用什么框架都存在着从controller向Html页面或者jsp页面传递数据的问题,最常用的方式是传递Json字符串。以前对这块知识有些模糊,现在整理一下。
![](https://upload-images.jianshu.io/upload_images/12577968-137801120e952fea.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/1240)
**【Jquery基本方法】**
实现传值常用的是Jquery以及内部封装的ajax。首先看一下jquery的get()和post()语法。get()方法是从服务器获得数据,其主要参数就是获得后台请求地址,以及负责处理的回调函数:
$.get(URL,callback);
```
$("button").click(function(){
$.get("demo_test.php",function(data,status){
alert("数据: " + data + "\n状态: " +
status);
});
});
```
**post通过HTTP post方法请求数据:**
$.post(URL,data,callback);
```
$("button").click(function(){
$.post("/try/ajax/demo_test_post.php",
{
name:"全栈