Monthly Archives: August 2014

retrieve data through ajax

In order to retrieve data via ajax, we give it some parameter data like requestId, andn telNum, then it will return a data through a data parameter. In our case, it is data.

JSON stringify

JSON.stringify turns an object in to a JSON text and stores that JSON text in a string.

鱼香肉丝 10 0.9 9 38 342
汉堡 15 0.9 13.5 46 621

Send html data via jQuery and AJAX to JSON url

You got whole bunch of data in textboxes and combo boxes. You retrieve those data by their id using jQuery like so:

Once you get these data…you pass it into ajax’s data parameter and you’re basically done:

single click on datagrid

This is how you detect single click on datagrids using easyui:


performSelectorOnMainThread and detachNewThreadSelector

from MobileAppMastery/Threading/02

Basically detachNewThreadSelector detaches a thread and starts its work process. When you need to update the UI, you do it on the main thread. We use performSelectorOnMainThread to do it. We make our main thread perform a chunk of code.

1) get the big task going with:

2) the big task will be running with a ridiculous for loop. Let’s remember to put everything within an autoreleasepool because we want the garbage collection to do its work right away within this cycle.

3) so we’re running happily and this big task is being finished on a separate thread. But what if we want to update the UI? We do it with the performSelectorOnMainThread method:

Basically we run a chunk of code on the main thread. This chunk of code in our case is getting the progress bar to set a new percentage.
Now, the other thing we have to take care of is WHEN do we do this update? In our case, we just do this every time it hits a thousand.
We keep the counter variable ‘updateUIWhen’ to increment by 1000 everytime we update the UI. That way, it i will run 1000 times more before
it does the next update.

Obviously, this is just an example of updating the UI incrementally. You can use whatever method you’d like.

full source:

Simple detachThread example

From MobileMasteryApp/threading/01

long task that blocks UI

In this example, we use the Activity Indicator to indicate the UI response. As you can see, when we start the loop to run through 40,000.


to make it start animating. However, on the emulator, you won’t see it moving because the current main thread will process the loop count. When it finishes, then it stops the animating. However, visually, you won’t see the indicator move at all.

Non blocking task

In this example, we detach a thread to do our long process for us. Thus, this spares the main thread of extra work. The main thread’s task is to update the UI and do little processing as possible. Leave the heavy lifting to separate threads.