callback

setTimeout - callback argument must be a function

混江龙づ霸主 提交于 2020-01-11 11:24:09
问题 My code was working until i updated node.js to version 8.11.3 Now i always get error "callback argument must be a function" when trying to call a function with setTimeout. function testFunction(itemid, price) { var url = 'https://example.com'; var options = { method: 'get', url: url } request(options, function (err, res, body) { var response = JSON.parse(body); if(response.status == 'fail'){ setTimeout(testFunction(itemid, price), 100); } }) } 回答1: Callback argument for setTimeout must be a

How can I use the Android back button to move back within my app instead of closing my app?

狂风中的少年 提交于 2020-01-11 10:35:09
问题 My app has three activities, A, B and C. I am moving from A to B through an OK button, and I want to move back from B to A by using the default back button of Android devices. When I press the button, though, the entire app gets closed. How can I get around this problem? 回答1: I suspect you call finish() in your OK button onclick listener. Don't do that. finish() removes your activity from activity stack. Read more here. 回答2: why start your activity for result ? when you press the backbutton,

angular $http / jquery complete equivalent

旧城冷巷雨未停 提交于 2020-01-11 08:05:14
问题 Is there a way to emulate jquery 'complete' callback with angular $http module? I have some code I would like to execute no matter whether the request succeeded or failed and at the moment I find myself having to write this: $http.get(someUrl).success(function(){ successCode(); completeCode(); }).error(function(){ errorCode(); completeCode(); }) but I would rather write something like: $http.get(someUrl).success(function(){ successCode(); }).error(function(){ errorCode(); }).complete(function

解决前后交互跨域访问问题的两种方法

假装没事ソ 提交于 2020-01-11 03:44:51
网上有很多方法,总结下,字不重要,直接上代码(亲测没有任何问题): 前端代码: //首先是万能的ajax方法 $.ajax({ url : "xxxxxxxxxxxx", //URL地址 type : "post", //请求方式 get 、post data : {}, //传入后台的参数 dataType:"jsonp", //如果跨域,必须改成jsonp格式的对象 jsonp:"callback", //Jquery生成验证参数的名称,callback会传入后台 success : function(json){ if(json.code!==200){ alert(json.msg) }else{ } } }); 后台代码: <!-- 添加JSONObject依赖--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.7</version> </dependency> import com.alibaba.fastjson.JSONObject; /** * 测试代码1 * @param callback * @return * @throws Exception */ @RequestMapping(value = "getxxx",

Erlang OTP学习(1)gen_server

谁说胖子不能爱 提交于 2020-01-10 20:25:09
在《Programming Erlang》的OTP introduction章节中,作者通过循序渐进的方式,向我们展示了gen_server设计思路,现在做下总结: 在具体看gen_server之前,我们先看一个server通用框架: 在这个server里,你几乎看不到任何和具体功能相关的东西,它只提供了一个server所具备的基本框架,那它是如何运行的呢? 当我们调用start函数时,就启动了一个服务,如果服务器接收到一条消息,那么它将会把这条消息转交给Mod:handle_call或者Mod:handle_cast处理 ,然后把执行结果返回给客户端(可选),接着继续等待新消息。 从这个过程中我们不难发现,服务器实际上充当着“代理”的角色,而真正处理客户端请求的其实是另外一个Module(我们称之为:callback模块) 这样有什么好处呢? 我谈谈自己的拙见: 1.解耦,把服务器功能部分和非公能部分分离,这样可以我们就可以更加专注于服务器功能模块的编写(即callback模块) 2.复用性,如果我们希望开发一个具有新功能的server,我们可以复用现有的server框架,然后编写具有新功能的callback Module即可 现在我们看一个callback Module例子(它提供了KV存储功能) 其中init, handle_call方法是用来供server端回调的,而add

nodejs之express 应用

蓝咒 提交于 2020-01-10 06:47:49
实例一 输出hello,world //express.js 服务端 // express module demo var express = require ( "express" ) ; var app = express ( ) ; app . get ( '/' , function ( req , res ) { res . send ( 'hello,world\n' ) ; } ) app . get ( '/user' , function ( req , res ) { res . send ( '/user get...\n' ) ; } ) var server = app . listen ( 8080 , function ( ) { var host = server . address ( ) . address ; var port = server . address ( ) . port ; console . log ( " http://%s:%s" , host , port ) ; } ) 在浏览器防卫或者curl 执行结果如下: 知识点 Express 应用使用回调函数的参数: request 和 response 对象来处理请求和响应的数据。 app . get ( '/' , function ( req , res ) { //

current OperationContext is null in WCF Windows Service

早过忘川 提交于 2020-01-10 04:54:59
问题 I am trying to set up a Publish/Subscribe system using WCF and where the WCF server is in a Windows service. The binding is net.TCP. The service is providing a "Subscribe" method to the client so the client can register a callback handler to an event that will be raised from a DLL linked to the server. In the Subscribe method I attempt to get the callback channel using the OperationContext.Current.GetCallbackChannel method. When I attempt this the OperationContext.Current property returns

函数对象 (伪函数)

一曲冷凌霜 提交于 2020-01-10 04:36:55
尽管函数指针被广泛用于实现函数回调,但C++还提供了一个重要的实现回调函数的方法,那就是函数对象。函数对象(也称“算符”)是重载了“()”操作符的普通类对象。因此从语法上讲,函数对象与普通的函数行为类似。 用函数对象代替函数指针有几个优点: 1>首先,因为对象可以在内部修改而不用改动外部接口,因此设计更灵活,更富有弹性。 2>函数对象也具备有存储先前调用结果的数据成员。 在使用普通函数时需要将先前调用的结果存储在全程或者本地静态变量中,但是全程或者本地静态变量有某些我们不愿意看到的缺陷。 3>其次,在函数对象中编译器能实现内联调用,从而更进一步增强了性能。这在函数指针中几乎是不可能实现的。 下面举例说明如何定义和使用函数对象。首先,声明一个普通的类并重载“()”操作符: class Square { public: int operator() (int n) { return n * n; } }; 重载操作语句中,记住第一个圆括弧总是空的,因为它代表重载的操作符名;第二个圆括弧是参数列表。一般在重载操作符时,参数数量是固定的,而重载“()”操作符时有所不同,它可以有任意多个参数。 因为在Square中内建的操作是一元的(只有一个操作数),重载的“()”操作符也只有一个参数。返回类型与参数类型相同-本例中为int。函数返回的是实参平方的整数。 使用函数对象 Square

Using this.setState in a callback

给你一囗甜甜゛ 提交于 2020-01-09 11:44:10
问题 I have the following code getting a twitter timeline in a react component: componentWillMount: function() { twitter.get('statuses/user_timeline', function(error, data) { this.setState({tweets: data}) }); } But I can't set the state there, because this isn't set to the component in that callback function. How can I set the state within that callback? n.b. console.log(data) instead of this.setState works fine, which is why I suspect the problem is with the this variable. 回答1: You can set this

Display nice error message when there is something wrong after ajax request jqgrid

淺唱寂寞╮ 提交于 2020-01-09 11:28:14
问题 I delete rows with this function: function deleteRow(){ rows = jQuery("#category_grid").getGridParam('selarrrow'); if( rows.length>0){ jQuery('#category_grid').delGridRow(rows,{ msg:'Verwijderen geselecteerde rijen?' }); }else{ alert("Selecteer eerst een rij om te verwijderen!"); } } but when it's fails in my php, server side and a exception is thrown. The errormessage looks not nice. How can i show errotext in the dialog box? or catch an error message after an ajax call? At the moment the