jQuery ajax – ajax() 方法 跨域请求
2018年4月18日不带数据get请求
1 2 3 4 5 6 7 8 9 10 |
$.ajax({ url: "/weeklydata", dataType: "json", type: "get", async: true, //异步 success: function (data) { weeklydata = data; } }); |
带数据post请求
1 2 3 4 5 6 7 8 9 10 |
$.ajax({ url: "/weeklydata", dataType: "json", type: 'POST', data: data, async: true, //异步 success: function (respond) { weeklydata = respond; } }); |
跨域请求
只支持get不支持post
1 2 3 4 5 6 7 8 9 |
$.ajax({ url: "http://localhost:9090/student", type: "GET", dataType: "jsonp", //指定服务器返回的数据类型 success: function (data) { var result = JSON.stringify(data); //json对象转成字符串 $("#text").val(result); } }); |