callback

Ajax基础原理与应用

余生颓废 提交于 2020-01-14 11:34:04
Ajax函数封装ajax.js // Get / Post // 参数 get post // 是否异步 // 如何处理响应数据 // URL // var handleResponse = function(response) { // // } // ajax.get('demo1.php', 'name=zhangsan&age=20', handleResponse, true) // ajax.post('demo1.php', 'name=zhangsan&age=20', handleResponse, true) function Ajax() { // 初始化方法 this.init = function() { this.xhr = new XMLHttpRequest(); }; // get请求方法 this.get = function(url, parameters, callback, async = true) { this.init(); if (async) { // 异步请求 this.xhr.onreadystatechange = function() { // this => this.xhr if (this.readyState == 4 && this.status == 200) { callback(this

Retrieving value from javascript callback function

这一生的挚爱 提交于 2020-01-14 05:00:09
问题 var display_welcome = function(){ var fb_login_button = jQuery('#fb_login_button'); var fb_welcome = jQuery('#fb_welcome'); var name = ''; FB.api('/me',function(response){ console.log(response); name = response.first_name; }); fb_login_button.css('display', 'none'); fb_welcome.html('<span>Welcome, ' + name + '</span>'); fb_welcome.css('display', 'block'); }; This function is called when a user logs into Facebook from a website. The goal is to display a welcome message to the user with the

google chrome extension update text after response callback

杀马特。学长 韩版系。学妹 提交于 2020-01-14 04:44:06
问题 I am writing a Google Chrome extension. I have reached the stage where I can pass messages back and forth readily but I am running into trouble with using the response callback. My background page opens a message page and then the message page requests more information from background. When the message page receives the response I want to replace some of the standard text on the message page with custom text based on the response. Here is the code: chrome.extension.sendRequest({cmd:

SignalR Connection Blocked Until page images load

天涯浪子 提交于 2020-01-14 03:33:07
问题 this is my signalr hub connection : chat = $.connection.chat; $.connection.hub.start().done(function () { // problem is here // this part is waiting for full page load.! }); why signalr connection waits for my page contents to load complete? i have a <img src='BAD SERVER'/> sometimes take 2 minutes to load successfully. and the connection is waiting for images loaded.! how can i fix this problem ? 回答1: Try this: chat = $.connection.chat; $.connection.hub.start({ waitForPageLoad: false }).done

OkHttp简单封装

一世执手 提交于 2020-01-14 01:42:30
public class OkHttpHelper { private String TAG = OkHttpHelper.class.getSimpleName(); private OkHttpClient mOkHttpClient;//okHttpClient 实例 private static OkHttpHelper mInstance = null; private Handler okHttpHandler;//全局处理子线程和M主线程通信 private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");//mdiatype 这个需要和服务端保持一致 public interface ReqCallBack<T> { /** * 响应成功 */ void onReqSuccess(T result); /** * 响应失败 */ void onReqFailed(String errorMsg); } private OkHttpHelper(Context context){ //初始化OkHttpClient mOkHttpClient = new OkHttpClient().newBuilder()

Pika 连接 rabbitmq 集群

余生颓废 提交于 2020-01-14 00:27:00
使用 Pika 连接 rabbitmq 集群 使用 python 编程经常会用到 pika 来向 rabbitmq 发送消息,单个 rabbitmq 节点连接比较简单,本文介绍使用 rabbitmq 集群情况下的连接方式。 vip 连接方式 在 client 与 rabbitmq server 之间通过 haproxy 等负载均衡来提供 vip,我使用的环境就是采用这种方式,但是遇到某一节点挂掉时再访问 vip 连接 rabbitmq 集群会连接失败,常见 log 如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <URLParameters host=10.10.11.1 port=5672 virtual_host=/ ssl=False> DEBUG:pika.adapters.select_connection:Using EPollPoller DEBUG:pika.callback:Added: { 'callback' : <bound method SelectConnection._on_connection_start of <SelectConnection CLOSED socket=None params =<URLParameters host=10.10.11.1 port=5672

non-member function pointer as a callback in API to member function

假装没事ソ 提交于 2020-01-13 14:04:13
问题 I'm using an API that requires me to pass a function pointer as a callback. I'm trying to use this API from my class in C++ but I'm getting compilation errors. The API definition is: typedef void (__stdcall *STREAM_CALLBACK)(void *userdata); __declspec(dllimport) int __stdcall set_stream_callback( STREAM_CALLBACK streamCB, void *userdata); One example file, provided by the third party, is: void __stdcall streamCB(void *userdata) { // callback implementation } int main(int argc, const char

Matlab gui WindowButtonMotionFcn crashes when called too often?

六月ゝ 毕业季﹏ 提交于 2020-01-13 11:24:30
问题 I've set WindowButtonMotionFcn to my callback which plots three plots, with the data depending on mouse position. However this seems to be too much for MATLAB to handle, because after moving my mouse around a bit, the GUI stops responding. I use this code (copied parts from someone): set(handles.figure1, 'windowbuttonmotionfcn', @hover_Callback); function hover_Callback(hObject, handles, eventdata) inside = false; pos = get(handles.axes1, 'currentpoint'); xlim = get(handles.axes1, 'XLim');

Matlab gui WindowButtonMotionFcn crashes when called too often?

你说的曾经没有我的故事 提交于 2020-01-13 11:24:06
问题 I've set WindowButtonMotionFcn to my callback which plots three plots, with the data depending on mouse position. However this seems to be too much for MATLAB to handle, because after moving my mouse around a bit, the GUI stops responding. I use this code (copied parts from someone): set(handles.figure1, 'windowbuttonmotionfcn', @hover_Callback); function hover_Callback(hObject, handles, eventdata) inside = false; pos = get(handles.axes1, 'currentpoint'); xlim = get(handles.axes1, 'XLim');

ASP.NET Client to Server communication

为君一笑 提交于 2020-01-13 11:02:28
问题 Can you help me make sense of all the different ways to communicate from browser to client in ASP.NET? I have made this a community wiki so feel free to edit my post to improve it. Specifically, I'm trying to understand in which scenario to use each one by listing how each works. I'm a little fuzzy on UpdatePanel vs CallBack (with ViewState): I know UpdatePanel always returns HTML while CallBack can return JSON. Any other major differences? ...and CallBack (without ViewState) vs WebMethod.