Search Results

Search found 523 results on 21 pages for 'callbacks'.

Page 4/21 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • jquery live and callbacks via wcf services

    - by vondip
    Hi all, I am writing a web app with asp.net, c# and jquery. Most of the time I'm writing dynamic html to the browser and using different web services to get the content needed. My call to the service: function WriteProducts(currentIndex, selectedCategoryId, callback) { var d = new Date(); MyAppServices.GetProducts(selectedCategoryId, currentIndex, 8, d.getTime().toString(), callback, function func() { alert('failure'); }); } The request usually gets translated to this (using firebug I monitored it): http://localhost:8080/MyApp/MyAppServices.svc/GetProducts?categoryId=0&fromIndex=0&toIndex=8&randomNumber=%221271800014441%22 The problem starts when part of the html controls dynamically rendered need to respond to click events. This is when I start using jquery's live method: $('.filter').live('click', function(event) { WriteProducts(0, selectedCategoryId, PopulateDivs); }); Now from some reason, the request passed to the server becomes this: http://localhost:8080/MyApp/MyAppServices.svc/GetProducts?categoryId=**%2217%22**&fromIndex=0&toIndex=8&randomNumber=%221271799783355%22 where did these %22 come from? If I take them out, the request passes successfully. I have no idea who inserted these %22, but they are causing havoc here! Guys, do you perhaps have a clue?

    Read the article

  • rails, activerecord callbacks not saving

    - by Joseph Silvashy
    I have a model with a callback that runs after_update: after_update :set_state protected def set_state if self.valid? self.state = 'complete' else self.state = 'in_progress' end end But it doesn't actually save those values, why not? Regardless of if the model is valid or not it won't even write anything, even if i remove the if self.valid? condition, I can't seem to save the state. Um, this might sound dumb, do I need to run save on it?

    Read the article

  • Ensuring that all callbacks were completed before sending a new request through a DuplexChannel usin

    - by Etan
    I am experiencing some issues when using a Callback in a WCF project. First, the server invokes some function Foo on the client which then forwards the request to a Windows Forms GUI: GUI CLASS delegate void DoForward(); public void ForwardToGui() { if (this.cmdSomeButton.InvokeRequired) { DoForward d = new DoForward(ForwardToGui); this.Invoke(d); } else { Process(); // sets result variable in callback class as soon as done } } } CALLBACK CLASS object _m = new object(); private int _result; public int result { get { return _result; } set { _result = value; lock(_m) { Monitor.PulseAll(_m); } } } [OperationContract] public int Foo() { result = 0; Program.Gui.ForwardToGui(); lock(_m) { Monitor.Wait(_m, 30000); } return result; } The problem now is that the user should be able to cancel the process, which doesn't work properly: SERVER INTERFACE [OperationContract] void Cleanup(); GUI CLASS private void Gui_FormClosed(object sender, EventArgs e) { Program.callbackclass.nextAction = -1; // so that the monitor pulses and Foo() returns Program.server.Cleanup(); } The problem with this is that Cleanup() hangs. However, when I close the form when Process() is not running, it works properly. The source seems to be that the Cleanup() is called before the monitor pulses etc and therefore a new request is sent to the server before the last request from the server has not yet been responded. How can I solve this problem? How can I ensure before calling Cleanup() that no Foo() is currently being executed?

    Read the article

  • Can twitter do callbacks?

    - by RenegadeAndy
    Hi! I am wondering if the twitter API supports the following: Whenever I make a post to my twitter account - it also calls a specific URL which I define so I can do something else? Thanks very much, Andy

    Read the article

  • Backbone: Easiest way to maintain reference to 'this' for a Model inside callbacks

    - by Garrett
    var JavascriptHelper = Backbone.Model.extend("JavascriptHelper", {}, // never initialized as an instance { myFn: function() { $('.selector').live('click', function() { this.anotherFn(); // FAIL! }); }, anotherFn: function() { alert('This is never called from myFn()'); } } ); The usual _.bindAll(this, ...) approach won't work here because I am never initializing this model as an instance. Any ideas? Thanks.

    Read the article

  • jquery: How to deal with 'this' in ajax callbacks

    - by Svish
    I currently have code similar to this for a form: $('#some-form') .submit(function() { // Make sure we are not already busy if($(this).data('busy')) return false; $(this).data('busy', true); // Do post $.post("some/url", $(this).serialize(), function(data) { if(data.success) // Success is a boolean I set in the result on the server { // Deal with data } else { // Display error } $('#some-form') .removeData('busy'); }); return false; }); My issue is that I would like to somehow remove the need for knowing the form id in the post callback. In the end where I remove the busy data from the form, I'd like to somehow not have that hard coded. Is there any way I can do this? Is there a way I can hand whatever is in this to the post callback function? Since I know the id right now, I can get around it by doing what I have done, but I'd like to know how to not be dependant on knowing the id, since often I don't have an id. (For example if I have a link in each row in a table and all the rows have the same click handler.

    Read the article

  • Call AsyncTask methods from another class/service (callbacks?)

    - by TiGer
    Hi, I was wondering if it's possible to call specific methods defined within the AsynTask class from another class and/or service ? In my specific case I have a Service playing some sounds, but the sound is selected from a List with available sounds... When a sounds is selected it is downloaded from my home server, this takes some time (not much, let's say around the 3-4 seconds, the sounds/effects aren't big in size)... So my problem at the moment is that I have a service to play those sounds, and when I select one I wanted to show a progressdialog... The way (if I understood correctly) is to use an AsyncTask, but the only thing the AsyncTask will do is telling my Service to play a specific sound from my server... So there is no "callback" from the service to the Asynctask... How can I achieve that ? How can I call a running AsyncTask, which sits in another class, and tell him all work is done and thus he can stop showing the ProgressDialog ? Or am I over-engineering it and there are other ways ? Thanks in advance...

    Read the article

  • Dart js.interop callbacks

    - by basheps
    How can I translate the following jquery code to Dart? I'm having difficulty getting the alert callback to work using js.interop. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> $(function () { $('p').hide('slow', function() { alert("The paragraph is now hidden"); }); }); </script> Any help is appreciated.

    Read the article

  • How to open multiple socket connections and do callbacks in PHP

    - by Click Upvote
    I'm writing some code which processes a queue of items. The way it works is this: Get the next item flagged as needing to be processed from the mysql database row. Request some info from a google API using Curl, wait until the info is returned. Do the remainder of the processing based on the info returned. Flag the item as processed in the db, move onto the next item. The problem is that on step # 2. Google sometimes takes 10-15 seconds to return the requested info, during this time my script has to remain halted and wait. I'm wondering if I could change the code to do the following instead: Get the next 5 items to be processed as usual. Request info for items 1-5 from google, one after the other. When the info for item 1 is returned, a 'callback' should be done which calls up a function or otherwise calls some code which then does the remainder of the processing on items 1-5. And then the script starts over until all pending items in db are marked processed. How can something like this be achieved?

    Read the article

  • How do you usually manage callbacks in Java using Swing library?

    - by none
    I'm quite new to the Java Swing programming, and GUI development as well. As a beginner, I'm currently reading Design Pattern, but finding what I'm looking for is quite hard, most of the times. So far, I've never had huge problems defining a view hierarchy - I just use to subclass component from component. But the hard-to-do here is how managing callbacks, which often become hard to maintain due to the hard code. During my last projects, I tried to separate GUI, Listener and Callbacker objects which cooperated together, but in this way it was really hard adding new features. So, which kind of best patterns or best practices do you tend to use when trying to maintain, add new features or even worst avoid to hard-code classes which manage callbacks method in this kind of frameworks (mainly Java Swing)?

    Read the article

  • Watching a variable for changes without polling.

    - by milkfilk
    I'm using a framework called Processing which is basically a Java applet. It has the ability to do key events because Applet can. You can also roll your own callbacks of sorts into the parent. I'm not doing that right now and maybe that's the solution. For now, I'm looking for a more POJO solution. So I wrote some examples to illustrate my question. Please ignore using key events on the command line (console). Certainly this would be a very clean solution but it's not possible on the command line and my actual app isn't a command line app. In fact, a key event would be a good solution for me but I'm trying to understand events and polling beyond just keyboard specific problems. Both these examples flip a boolean. When the boolean flips, I want to fire something once. I could wrap the boolean in an Object so if the Object changes, I could fire an event too. I just don't want to poll with an if() statement unnecessarily. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * Example of checking a variable for changes. * Uses dumb if() and polls continuously. */ public class NotAvoidingPolling { public static void main(String[] args) { boolean typedA = false; String input = ""; System.out.println("Type 'a' please."); while (true) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); try { input = br.readLine(); } catch (IOException ioException) { System.out.println("IO Error."); System.exit(1); } // contrived state change logic if (input.equals("a")) { typedA = true; } else { typedA = false; } // problem: this is polling. if (typedA) System.out.println("Typed 'a'."); } } } Running this outputs: Type 'a' please. a Typed 'a'. On some forums people suggested using an Observer. And although this decouples the event handler from class being observed, I still have an if() on a forever loop. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Observable; import java.util.Observer; /* * Example of checking a variable for changes. * This uses an observer to decouple the handler feedback * out of the main() but still is polling. */ public class ObserverStillPolling { boolean typedA = false; public static void main(String[] args) { // this ObserverStillPolling o = new ObserverStillPolling(); final MyEvent myEvent = new MyEvent(o); final MyHandler myHandler = new MyHandler(); myEvent.addObserver(myHandler); // subscribe // watch for event forever Thread thread = new Thread(myEvent); thread.start(); System.out.println("Type 'a' please."); String input = ""; while (true) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); try { input = br.readLine(); } catch (IOException ioException) { System.out.println("IO Error."); System.exit(1); } // contrived state change logic // but it's decoupled now because there's no handler here. if (input.equals("a")) { o.typedA = true; } } } } class MyEvent extends Observable implements Runnable { // boolean typedA; ObserverStillPolling o; public MyEvent(ObserverStillPolling o) { this.o = o; } public void run() { // watch the main forever while (true) { // event fire if (this.o.typedA) { setChanged(); // in reality, you'd pass something more useful notifyObservers("You just typed 'a'."); // reset this.o.typedA = false; } } } } class MyHandler implements Observer { public void update(Observable obj, Object arg) { // handle event if (arg instanceof String) { System.out.println("We received:" + (String) arg); } } } Running this outputs: Type 'a' please. a We received:You just typed 'a'. I'd be ok if the if() was a NOOP on the CPU. But it's really comparing every pass. I see real CPU load. This is as bad as polling. I can maybe throttle it back with a sleep or compare the elapsed time since last update but this is not event driven. It's just less polling. So how can I do this smarter? How can I watch a POJO for changes without polling? In C# there seems to be something interesting called properties. I'm not a C# guy so maybe this isn't as magical as I think. private void SendPropertyChanging(string property) { if (this.PropertyChanging != null) { this.PropertyChanging(this, new PropertyChangingEventArgs(property)); } }

    Read the article

  • Facebook "Like" button callback

    - by Matt
    Hello, I am interested in implementing the facebook "Like" button, but I would like to know what user is clicking on this button so I can get some useful information from this. From what I have read, facebook is leaving us in the dark on who is clicking on what. ANyone have an idea on how I could track which user clicked on a like button for a particular product?

    Read the article

  • Calling matlab callback/function handle from Java

    - by jakob
    How do I pass a matlab function handle to a Java object and invoke it from within Java (that is, I want Java to tell matlab when it is ready with a calculation). I am trying to use the com.mathworks.jmi.Matlab class for evaluating Matlab expressions in the Java object, but I can't see how to 1) transfer the callback funcktion handle to Java, and 2) invoke it from Java possibly using the com.mathworks.jmi.Matlab class. Thanks, jakob

    Read the article

  • -[NSCFData writeStreamHandleEvent:]: unrecognized selector sent to instance in a stream callback

    - by user295491
    Hi everyone, I am working with streams and sockets in iPhone SDK 3.1.3 the issue is when the program accept a callback and I want to handle this writestream callback the following error is triggered " Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSCFData writeStreamHandleEvent:]: unrecognized selector sent to instance 0x17bc70'" But I don't know how to solve it because everything seems fine. Even when I run the debugger there is no error the program works. Any hint here will help! The code of the callback is: void myWriteStreamCallBack (CFWriteStreamRef stream, CFStreamEventType eventType, void *info){ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Connection *handlerEv = [(Connection *)info retain] autorelease]; [handlerEv writeStreamHandleEvent:eventType]; [pool release]; } The code of the writeStreamHandleEvent: - (void)writeStreamHandleEvent:(CFStreamEventType) eventType{ switch(eventType) { case kCFStreamEventOpenCompleted: writeStreamOpen = YES; break; case kCFStreamEventCanAcceptBytes: NSLog(@"Writing in the stream"); [self writeOutgoingBufferToStream]; break; case kCFStreamEventErrorOccurred: error = CFWriteStreamGetError(writeStream); fprintf(stderr, "CFReadStreamGetError returned (%ld, %ld)\n", error.domain, error.error); CFWriteStreamUnscheduleFromRunLoop(writeStream, CFRunLoopGetCurrent(),kCFRunLoopCommonModes); CFWriteStreamClose(writeStream); CFRelease(writeStream); break; case kCFStreamEventEndEncountered: CFWriteStreamUnscheduleFromRunLoop(writeStream, CFRunLoopGetCurrent(),kCFRunLoopCommonModes); CFWriteStreamClose(writeStream); CFRelease(writeStream); break; } } The code of the stream configuration: CFSocketContext ctx = {0, self, nil, nil, nil}; CFWriteStreamSetClient (writeStream,registeredEvents, (CFWriteStreamClientCallBack)&myWriteStreamCallBack,(CFStreamClientContext *)(&ctx) ); CFWriteStreamScheduleWithRunLoop (writeStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); You can see that there is nothing strange!, well at least I don't see it. Thank you in advance.

    Read the article

  • Using Api to submit userdata to external party

    - by Younes
    I have to submit subscription data to another website. I have got documentation on how to use this API however i'm not 100% sure of how to set this up. I do have all the information needed, like username / passwords etc. This is the API documentation: https://www.apiemail.net/api/documentation/?SID=4 How would my request / post / whatever look like in C# .net (vs 2008) when i'm trying to acces this API? This is what i have now, I think i'm not on the right track: public static string GArequestResponseHelper(string url, string token, string username, string password) { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); myRequest.Headers.Add("Username: " + username); myRequest.Headers.Add("Password: " + password); HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); Stream responseBody = myResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader(responseBody, encode); //return string itself (easier to work with) return readStream.ReadToEnd();

    Read the article

  • C#: My callback function gets called twice for every Sent Request

    - by Madi D.
    I've Got a program that uploads/downloads files into an online server,Has a callback to report progress and log it into a textfile, The program is built with the following structure: public void Upload(string source, string destination) { //Object containing Source and destination to pass to the threaded function KeyValuePair<string, string> file = new KeyValuePair<string, string>(source, destination); //Threading to make sure no blocking happens after calling upload Function Thread t = new Thread(new ParameterizedThreadStart(amazonHandler.TUpload)); t.Start(file); } private void TUpload(object fileInfo) { KeyValuePair<string, string> file = (KeyValuePair<string, string>)fileInfo; /* Some Magic goes here,Checking The file and Authorizing Upload */ var ftiObject = new FtiObject () { FileNameOnHDD = file.Key, DestinationPath = file.Value, //Has more data used for calculations. }; //Threading to make sure progress gets callback gets called. Thread t = new Thread(new ParameterizedThreadStart(amazonHandler.UploadOP)); t.Start(ftiObject); //Signal used to stop progress untill uploadCompleted is called. uploadChunkDoneSignal.WaitOne(); /* Some Extra Code */ } private void UploadOP(object ftiSentObject) { FtiObject ftiObject = (FtiObject)ftiSentObject; /* Some useless code to create the uri and prepare the ftiObject. */ // webClient.UploadFileAsync will open a thread that // will upload the file and report // progress/complete using registered callback functions. webClient.UploadFileAsync(uri, "PUT", ftiObject.FileNameOnHDD, ftiObject); } I got a callback that is registered to the Webclient's UploadProgressChanged event , however it is getting called twice per sent request. void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e) { FtiObject ftiObject = (FtiObject )e.UserState; Logger.log(ftiObject.FileNameOnHDD, (double)e.BytesSent ,e.TotalBytesToSend); } Log Output: Filename: C:\Text1.txt Uploaded:1024 TotalFileSize: 665241 Filename: C:\Text1.txt Uploaded:1024 TotalFileSize: 665241 Filename: C:\Text1.txt Uploaded:2048 TotalFileSize: 665241 Filename: C:\Text1.txt Uploaded:2048 TotalFileSize: 665241 Filename: C:\Text1.txt Uploaded:3072 TotalFileSize: 665241 Filename: C:\Text1.txt Uploaded:3072 TotalFileSize: 665241 Etc... I am watching the Network Traffic using a watcher, and only 1 request is being sent. Some how i cant Figure out why the callback is being called twice, my doubt was that the callback is getting fired by each thread opened(the main Upload , and TUpload), however i dont know how to test if thats the cause. Note: The reason behind the many /**/ Comments is to indicate that the functions do more than just opening threads, and threading is being used to make sure no blocking occurs (there a couple of "Signal.WaitOne()" around the code for synchronization)

    Read the article

  • Matlab GUI - How to get the previous value entered from a callback function?

    - by Graham
    Hi, I know that this is probably a simple problem but I am new to Matlab GUI's and basically want to get the old value which used to be stored in the text box to replace the value which has just been entered. E.g. Text box contains a valid string, User enters invalid string, Callback func, validates input and realises new input is an error and reverts to the old previous value. How should this be implemented or done? Atm I am just using the get and set property values. Below is some sample code: function sampledist_Callback(hObject, eventdata, handles) % hObject handle to sampledist (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of sampledist as text % str2double(get(hObject,'String')) returns contents of sampledist as a double input = str2double(get(hObject,'String')); if(input < 0 || input > 500) errordlg('Sampled Dist. must be > 0 and < 500','Sample Dist - Input Error'); set(handles.sampledist,'String',['10']); %<--- I would like this value 10 to be the previous entry! guidata(hObject,handles); else set(handles.sampledist,'String',['',input]); guidata(hObject,handles); end

    Read the article

  • Using callback functions for error handling in C

    - by Earlz
    Hi, I have been thinking about the difficulty incurred with C error handling.. like who actually does if(printf("hello world")==-1){exit(1);} But you break common standards by not doing such verbose, and usually useless coding. Well what if you had a wrapper around the libc? like so you could do something like.. //main... error_catchall(my_errors); printf("hello world"); //this will automatically call my_errors on an error of printf ignore=1; //this makes it so the function will return like normal and we can check error values ourself if(fopen.... //we want to know if the file opened or not and handle it ourself. } int my_errors(){ if(ignore==0){ _exit(1); //exit if we aren't handling this error by flagging ignore } return 0; //this is called when there is an error anywhere in the libc } ... I am considering making such a wrapper as I am synthesizing my own BSD licensed libc(so I already have to touch the untouchable..), but I would like to know what people think about it.. would this actually work in real life and be more useful than returning -1?

    Read the article

  • How can I determine/use $(this) in js callback script

    - by Rabbott
    I am using Rails and jQuery, making an ajax call initiated by clicking a link. I setup my application.js file to look like the one proposed here and it works great. The problem I'm having is how can I use $(this) in my say.. update.js.erb file to represent the link I clicked? I don't want to have to assign an ID to every one, then recompile that id in the callback script.. EDIT To give a simple example of something similar to what I'm trying to do (and much easier to explain): If a user clicks on a link, that deletes that element from a list, the controller would handle the callback, and the callback (which is in question here) would delete the element I clicked on, so in the callback delete.js.erb would just say $(this).fadeOut(); This is why I want to use $(this) so that I dont have to assign an ID to every element (which would be the end of the world, just more verbose markup) application.js jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript,application/javascript,text/html")} }) function _ajax_request(url, data, callback, type, method) { if (jQuery.isFunction(data)) { callback = data; data = {}; } return jQuery.ajax({ type: method, url: url, data: data, success: callback, dataType: type }); } jQuery.extend({ put: function(url, data, callback, type) { return _ajax_request(url, data, callback, type, 'PUT'); }, delete_: function(url, data, callback, type) { return _ajax_request(url, data, callback, type, 'DELETE'); } }); jQuery.fn.submitWithAjax = function() { this.unbind('submit', false); this.submit(function() { $.post(this.action, $(this).serialize(), null, "script"); return false; }) return this; }; // Send data via get if <acronym title="JavaScript">JS</acronym> enabled jQuery.fn.getWithAjax = function() { this.unbind('click', false); this.click(function() { $.get($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; // Send data via Post if <acronym title="JavaScript">JS</acronym> enabled jQuery.fn.postWithAjax = function() { this.unbind('click', false); this.click(function() { $.post($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; jQuery.fn.putWithAjax = function() { this.unbind('click', false); this.click(function() { $.put($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; jQuery.fn.deleteWithAjax = function() { this.removeAttr('onclick'); this.unbind('click', false); this.click(function() { $.delete_($(this).attr("href"), $(this).serialize(), null, "script"); return false; }) return this; }; // This will "ajaxify" the links function ajaxLinks(){ $('.ajaxForm').submitWithAjax(); $('a.get').getWithAjax(); $('a.post').postWithAjax(); $('a.put').putWithAjax(); $('a.delete').deleteWithAjax(); } show.html.erb <%= link_to 'Link Title', article_path(a, :sentiment => Article::Sentiment['Neutral']), :class => 'put' %> The combination of the two things will call update.js.erb in rails, the code in that file is used as the callback of the ajax ($.put in this case) update.js.erb // user feedback $("#notice").html('<%= flash[:notice] %>'); // update the background color $(this OR e.target).attr("color", "red");

    Read the article

  • C# wrapper of c++ dll; "Run-Time Check Failure #0 - The value of ESP was not properly saved across a

    - by Deveti Putnik
    Here is the code in C++ dll: extern "C" _declspec(dllexport) int testDelegate(int (*addFunction)(int, int), int a, int b) { int res = addFunction(a, b); return res; } and here is the code in C#: public delegate int AddIntegersDelegate(int number1, int number2); public static int AddIntegers(int a, int b) { return a + b; } [DllImport("tester.dll", SetLastError = true)] public static extern int testDelegate(AddIntegersDelegate callBackProc, int a, int b); public static void Main(string[] args) { int result = testDelegate(AddIntegers, 4, 5); Console.WriteLine("Code returned:" + result.ToString()); } When I start this small app, I get the message from the header of this post. Can someone help, please? Thanks in advance, D

    Read the article

  • Implementing an ActiveRecord before_find

    - by thaiyoshi
    I am building a search with the keywords cached in a table. Before a user-inputted keyword is looked up in the table, it is normalized. For example, some punctuation like '-' is removed and the casing is standardized. The normalized keyword is then used to find fetch the search results. I am currently handling the normalization in the controller with a before_filter. I was wondering if there was a way to do this in the model instead. Something conceptually like a "before_find" callback would work although that wouldn't make sense on for an instance level.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >