格式和参数:
url (String) : 发送请求的URL地址。
data (Map):(可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。
callback (Function): (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。
type (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等)。
案例代码: ajax.htm
IT小奋斗$(document).ready(function(){
// Ajax GET
$("#getBnt").click(function(){
var v = $("input[name='get']").val();
// GET请求
$.get("/tool/ajax.html", function(result){
$("div").html(result);
});
});
// Ajax GET
$("#getBnt2").click(function(){
var v = $("input[name='get']").val();
// GET请求
$.get("/tool/ajax.html?name=name&value=" + v, function(result){
$("div").html(result);
});
});
$("#getBnt3").click(function(){
var v = $("input[name='get']").val();
// GET请求
$.get("/tool/ajax.html",{ name: "name", value: v }, function(result){
$("div").html(result);
});
});
});