Fetch the the data asynchronous?



Hi All,

I have a observable variable binding to page.

var viewModel = observableModule.fromObject({
      search: ""
exports.pageLoaded = function(args) {
    var page = args.object;
    page.bindingContext = viewModel;

    viewModel.on('propertyChange', function (propertyChangeData) {
        if (propertyChangeData.propertyName == "search") {
            fetchModule.fetch(apiPath, postObj).then(function(res){
                 //Do changes

But when i enter each server communication is happening. SO app is not working till response came. So i want kill previous server call and send latest call to server so i can get smooth navigation


Cancelling a HTTP Request is still a open feature request in NativeScript. You may vote and follow up this ticket here.

But may be you can hack it by processing the data only when your current search query and response’s search param are same.


Hi @Manojdcoder,

Do we have an other alternative to get solution. Because if the response is too heavy so user can not wait until that. So he can continue text entering in the field. It may irritate the user.


What you are doing is already async, I’m not quite sure why you think still user has to wait for response for him to proceed further.

As user types event will keep on firing with updated values and you are going to hit the server with fetch module. Only when processing the response, you have to make sure it is response of latest request.

You may also implement some logic using timeout / debounce to make server request less frequently as user types.

If you are really interested in getting cancel work, it’s possible if you have the time and understand how to modify or override the http client’s source Or hire the right person to do it for you.