Skip to main content

Posts

Showing posts with the label callback

jQuery / Ajax - $.ajax() Passing Parameters to Callback - Good Pattern to Use?

JavaScript code I'm starting with: function doSomething(url) { $.ajax({ type: "GET", url: url, dataType: "xml", success: rssToTarget }); } Pattern I would like to use: //where elem is the target that should receive new items via DOM (appendChild) function doSomething(url, elem) { $.ajax({ type: "GET", url: url, dataType: "xml", success: rssToTarget(elem) }); } I don't think I can get the callback to work this way, right? What is the proper pattern? I don't want to use global variables necessarily to temporarily hold the elem or elem name. Source: Tips4all

JavaScript: asynchronous function that resumes to synchronous

I have a large script that is very synchronous. 1) it runs a function like this: var result = doSomethingSynchronous(myVar); if (result === 'something') { doSomethingElse(); } the doSomethingSynchronous function has a for loop that returns a value on a if statement: var i = 0; le = someVariable.length; for (; i < len; i++) { if (someVariable[i] === 'aString') { return true; } else { doSomethingElse(); } } Because the for loop and the processing can be intense, I've replaced the for loop with an iterative queue processing function that runs itself asynchronously using setTimeout after shifting one element from the array. Once it runs asynchronously of course it doesn't return the value and assigns it to the 'result' variable in the first snippet synchronously, and the if statement there always fails. My question is, is there a way to keep this part synchronous? Have the value be assigned to result before the script goes on to th

method called after release() exception unable to resume with android camera

while developing a camera app i'v encountered an exception that only happend when I switch to other intent (onPause for my app) or go to preference in my app(same, onPause) 01-15 17:22:15.017: E/AndroidRuntime(14336): FATAL EXCEPTION: main 01-15 17:22:15.017: E/AndroidRuntime(14336): java.lang.RuntimeException: Method called after release() 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.hardware.Camera.setPreviewDisplay(Native Method) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.hardware.Camera.setPreviewDisplay(Camera.java:357) 01-15 17:22:15.017: E/AndroidRuntime(14336): at com.sora.cbir.yuki.image.leaf.CameraPreview.surfaceCreated(CameraPreview.java:32) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.view.SurfaceView.updateWindow(SurfaceView.java:551) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:213) 01-15 17:22:15.017: E/AndroidRuntime(14336): at android.view.V