Question: There are lines:

```
echo "1111111111111; 2222222222; 8; 2; 34,12,2,3,5,1; UNKNOW;"

```

or

```
echo "1111111111111; 2222222222; 8; 2; 34,12,2,3,5,1,5,12,45,34; UNKNOW;"

```

or

```
echo "1111111111111; 2222222222; 8; 2; 3; UNKNOW;"

```

How to take the value of the last character ";" and to the last comma ","?

Answer: 
So your best bet is to give yourself a bit of delay. As noted by Akash, you have to choose the delay time you find acceptable. You also need to make sure that the request is only made after the delay.

Here is one way to do it:

```
//In your controller
var _timeout;

$scope.fetchSearchResults = function(){

    //We will clear the previous timeout because a key has been pressed
    clearTimeout(_timeout);

    //Set the timeout - if no key is pressed, it will execute. Else the line above will clear it.
    _timeout =  setTimeout(function(){
        var keyword = $scope.searchKeyword.name;
        //Do your AJAX request here

        //We have delayed the request by 400ms - but you can change it as you please.
    }, 400);
}

```

Your HTML:

```
<!-- Then in your HTML something similar to: -->
<input ng-model="searchKeyword.name" ng-keyup="fetchSearchResults()" />

```

**Edit:**

If you want to go the 'pure' angular way, you'd do it like this:

```
//In your controller
//NOTE: make sure you've injected $timeout into your controller
var _timeout;

$scope.fetchSearchResults = function(){

    //We will clear the previous timeout because a key has been pressed
    $timeout.cancel(_timeout);

    //Set the timeout - if no key is pressed, it will execute. Else the line above will clear it.
    _timeout =  $timeout(function(){
        var keyword = $scope.searchKeyword.name;
        //Do your AJAX request here

        //We have delayed the request by 400ms - but you can change it as you please.
    }, 400);
}

```
I definitely recommend @jeanpaul's answer for "debouncing".

In addition to that, when you have potential for multiple concurrent AJAX requests and you want to handle the most recent one, it can be necessary to verify which request it is in your response handler. This is especially important when the responses don't always come in the same order they were requested (ie. an earlier request takes longer to respond than a later one)

A way to solve this is something like:

```
var activeRequest;
function doRequest(params){
    // reqId is the id for the request being made in this function call
    var reqId = angular.toJson(params); // I usually md5 hash this

    // activeRequest will always be the last reqId sent out
    activeRequest = reqId; 

    $http.get('/api/something', {data: params})
        .then(function(res){
            if(activeRequest == reqId){
                // this is the response for last request
            }
            else {
                // response from previous request (typically gets ignored)
            }
        });
}

```