在meteor中使用支付,以及与服务器进行数据交互

本文介绍如何在 Meteor 应用中使用 HTTP 模块进行服务器端请求,包括安装 http 包、使用 wrapAsync 封装异步方法、解决常见错误等。还涉及了 ejson 的使用及第三方插件的添加。

how to use Meteor.http.call?

Meteor.http is only available on sever side

http模块仅能用于server端。

1,add http

meteor add http

2, 使用wrapAsync封装异步调用

Meteor.methods({
    hello:function(){
        console.log("server");
        var postTest = function (cb) {
            Meteor.http.post("http://app.lawxin.com/version",
                {data: {},headers: {
                    //"content-type":"application/json",
                    "Accept":"application/json"
                }},
                function (error, result) {
                    console.log("content", JSON.stringify(result));
                    cb && cb(error, result);
                });
        };

        return Meteor.wrapAsync(postTest)();
    }
...

  

cb是callback,是必须调用的。cb的格式须是function(error,result){}格式。

3,错误:ERROR whitelist rejection

mobile-config.js:

App.accessRule('*');

  

4,add cordova pingxx plugin 

meteor add cordova:co.airsia.cordova.pingpp@https://github.com/TongChia/cordova-plugin-pingpp/tarball/b7bdf93a7fbda003a8fab44967bfa5fc36488731 

这个插件在添加时需要参数,这样添加:

mobile-config.js:
App.configurePlugin('co.airsia.cordova.pingpp', {
URL_SCHEME: 'meteorionic'
});

5,使用ejson

meteor add ejson

主要方法:

EJSON.parse
EJSON.stringify

6,错误:error charge object

function(error,result)

该方法中返回的result是string格式。

源码:http://vdisk.weibo.com/s/ao-ZYIoZdaYwE

效果图:

 

转载于:https://www.cnblogs.com/sban/p/4702799.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值