1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/pandao-httpx.js

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
Внести вклад в разработку кода
Синхронизировать код
Отмена
Подсказка: Поскольку Git не поддерживает пустые директории, создание директории приведёт к созданию пустого файла .keep.
Loading...
README.md

Библиотека httpx.js: простые запросы HTTP/RESTful на JavaScript (XHR)

Описание:

Библиотека httpx.js — это простая библиотека запросов HTTP/RESTful на языке JavaScript, основанная на XMLHttpRequest (XHR). Поддерживает XHR1 (XMLHttpRequest Level 1) и обещает поддержку XHR2 (XMLHttpRequest Level 2) в будущем.

Установка:

bower install httpx.js --save
# или
npm install httpx.js --save

Методы:

  • GET;
  • POST;
  • PUT;
  • PATCH;
  • DELETE;
  • JSON (псевдоним getJSON);
  • JSONP;
  • getScript.

Совместимость:

  • Firefox 4.0+;
  • Chrome 7+;
  • IE 9+;
  • Opera 11.60+;
  • Safari 5.1.4+.

Примеры:

Описание:

get|post|put|patch|delete|json(alias getJSON)(url, [data], [callback], [error], [options]);

GET:

httpx.get("http://localhost/http-test/get.php?foo=Level1&bar=XHR&zh=中文", function(data) {
    //console.log(data, this);
}, function(method, url) {
    console.error("Custom Error", method, url, this.status, this.statusText);
});

POST:

httpx.post("http://localhost/http-test/post.php?edfd=eedfd&dfsdf=ere", {
    a : 12,
    b : "bbbb",
    c : 123489
}, function(data) {
    console.log(data, this);
});

PUT:

httpx.put("http://localhost/http-test/put.php?edfd=eedfd&dfsdf=ere", {
    a : 12,
    b : "bbbb",
    c : 123489
}, function(data) {
    console.log(data, this);
});

PATCH:

httpx.patch("http://localhost/http-test/patch.php?edfd=eedfd&dfsdf=ere", {
    a : 12,
    b : "bbbb",
    c : 123489
}, function(data) {
    console.log(data, this);
});

DELETE:

httpx.delete("http://localhost/http-test/delete.php?edfd=eedfd&dfsdf=ere", {
    a : 12,
    b : "bbbb",
    c : 123489
}, function(data) {
    console.log(data, this);
});

JSON (get json):

// Alias getJSON(), like jQuery
httpx.json("http://localhost/http-test/get-json.php?temp="+(new Date).getTime(), {
    test : 123
}, function(json) {
    console.log("get json =>", json);
});

JSONP: jsonp(url, [data], [callback], [callbackName]); // callbackName for query string name

httpx.jsonp("http://192.168.1.2/http-test/jsonp.php?temp="+(new Date).getTime(), {
    test : 123
}, function(json) {
    console.log("jsonp =>", json);
}, "callback");

getScript:

httpx.getScript("http://192.168.1.2/http-test/test.js", function() {
    test();
});

Опции:

По умолчанию:

{
    debug         : false,
    async         : true,
    timeout       : 3000,
    method        : "GET",
    url           : "",
    data          : "",
    dataType      : "text",
    headers       : {},
    contentType   : "text/plain; charset=UTF-8",
    jsonp         : "callback",    // for query string
    xhrFields     : { //  like jQuery xhrFields options
        withCredentials : false
    },
    sendBefore    : function(xhr) {
        return xhr; // or return this, this == xhr
    },
    success       : function() {},
    error         : function(method, url) {},
    ontimeout     : function(method, url) {}
}

Использование:

httpx.request({
    url : "http://localhost/http-test/head.php",
    method : "HEAD",  // Custom http method
    headers : {},  // Custom http headers
    success : function(data) {
    	console.log(data, this, this.$request);
    }
});

httpx.get({
    url : "http://localhost/http-test/get.php?foo=bar",
    headers : {
    	"xxxxxxx" : "xxxxx"
    },
    success : function(data) {
    	console.log(data, this, this.$request);
    }
});

httpx.post({
    url : "http://localhost/http-test/post.php?foo=bar",
    data : {
    	id : 123,
    	title : "xxxxx"
    },
    headers : {
    	"xxxxxxx" : "xxxxx"
    },
    success : function(data) {
    	console.log(data, this, this.$request);
    }
});

// put/patch/delete/json ...

Разработка:

# init
npm install

# develop
gulp watch
# or npm run dev

# production
gulp build
# or npm run build

Изменения: Журнал изменений.

Лицензия:

Лицензия MIT.

Авторские права (c) 2015~2017 Pandao.

Комментарии ( 0 )

Вы можете оставить комментарий после Вход в систему

Введение

Простая библиотека запросов HTTP/RESTful на JavaScript (XHR). Развернуть Свернуть
MIT
Отмена

Обновления

Пока нет обновлений

Участники

все

Недавние действия

Загрузить больше
Больше нет результатов для загрузки
1
https://api.gitlife.ru/oschina-mirror/pandao-httpx.js.git
git@api.gitlife.ru:oschina-mirror/pandao-httpx.js.git
oschina-mirror
pandao-httpx.js
pandao-httpx.js
master