HTTP/RESTful 请求库 httpx.js

码农软件 · 软件分类 · REST/RESTful项目 · 2019-03-10 22:56:53

软件介绍

httpx.js 是一个简单的  JavaScript HTTP/RESTful 请求库。

主要方法

  • GET

  • POST

  • PUT

  • PATCH

  • DELETE

  • Other

  • JSON

  • 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]);

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);
});

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(getJSON):

// 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();
});

选项



{
    async         : true,
    timeout       : 3000,
    method        : "GET",
    url           : "",
    data          : "",
    dataType      : "text",
    headers       : {},
    contentType   : "text/plain; charset=UTF-8",
    jsonp         : "callback",    // for query string
    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);
    }
});

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

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);
    }
});

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

本文地址:https://codercto.com/soft/d/1077.html

《Unity3D网络游戏实战(第2版)》

《Unity3D网络游戏实战(第2版)》

罗培羽 / 机械工业出版社 / 2019-1-1 / 89.00元

详解Socket编程,搭建稳健的网络框架;解决网游中常见的卡顿、频繁掉线等问题;探求适宜的实时同步算法。完整的多人对战游戏案例,揭秘登录注册、游戏大厅、战斗系统等模块的实现细节。 想要制作当今热门的网络游戏,特别是开发手机网络游戏,或者想要到游戏公司求职,都需要深入了解网络游戏的开发技术。本书分为三大部分,揭示网络游戏开发的细节。 第一部分“扎基础”(1-5章) 介绍TCP网络游......一起来看看 《《Unity3D网络游戏实战(第2版)》》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具