在AngularJS中主要使用$http服務(wù)與遠(yuǎn)程http服務(wù)器交互,其作用類似于jquery中的$.ajax服務(wù):
$http使用說明:
$http服務(wù)使用如下面代碼所示:
// 1.5以下版本$http(config).success(function(data, status, headers, config){//請求成功執(zhí)行代碼}).error(function(data, status, headers, config){//請求失敗執(zhí)行代碼})// 1.5以上版本$http(config).then(function successCallback(response){//請求成功執(zhí)行代碼},function errorCallback(response){//請求失敗執(zhí)行代碼});
具體參數(shù)、方法說明:
配置參數(shù):
回調(diào)函數(shù):
method屬性可以作為config配置參數(shù)中的一個屬性,也可以直接作為方法調(diào)用,如:
$http.post(url, data, config)
$http使用范例:
var searchOplog = function ($http, table, btn) { $http({ url: 'data/oplog.json', method: 'GET' }).then(function successCallback(response) { console.log('get Oplog success:', response); table.init(response.data); btn.button('reset'); btn.dequeue(); }, function errorCallback(response) { console.log('errorCallback Response is:', response); table.init(); btn.button('reset'); btn.dequeue(); });};
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答