$.get("json/countries.json", // String {"key1":"value1","key2":"value2","key3":"第三个值"}, //data Map function(data, textStatus, xhr){ console.log("success" + textStatus + "\n" + xhr.responseText); array = xhr.response; }, // success function callback Function "json" ); // type string 参数顺序不能乱
/* 参数: url,[data],[callback],[type] String,Map,Function,String * */ $.post("url", {"key1":"value1","key2":"value2","key3":"第三个值"}, //data Map function(data, textStatus, xhr){ console.log("success" + textStatus + "\n" + xhr.responseText); array = xhr.response; }, // success function callback Function "json" );
$.ajax({ type:"get", url:"json/countries.json", async:true, complete:function(xhr, textStatus){ console.log("complete" + textStatus); }, success:function(data, textStatus, xhr){ console.log("success" + textStatus); }, error:function(data, textStatus, xhr) { console.log("error" + textStatus); } });
$.ajax("json/countries.json") .complete(function(xhr, textStatus) { console.log("complete" + textStatus); }).success(function(data, textStatus, xhr) { // console.log("success" + textStatus); }).error(function(data, textStatus, xhr) { // console.log("error" + textStatus); });