Search code examples
ajaxgrailsgroovygsp

Continue Ajax call for table data till the text not found


I've list of data like...

| Coloumn1 | Coloumn2 | Coloumn3  |
|----------|----------|-----------|
| val1     | val2     | val3      |
| val1     | ' '      | val3      |

The above table I've on form submit, now after some time I found the value of Coloumn2 instead of ' '/BLANK, So I want to put it into the table without reload the page.

I've following code structure...

myInstance.gsp

<tbody id="myInstanceTData">
<g:each in="${myInstanceList}" var="myInstance">
<tr id="${myInstance?.id}">
        <td class="align-center zoomout">
        <td class="align-center">${myInstance?.text?:"N/A"}</td>
        </td>
        <td class="align-center" style="color:${myInstance?.objectColor}">
            <g:if test="${myInstance?.object}">
                ${myInstance.object}
            </g:if>
            <g:else>
                ${"Second Analytics"}<br>${"In-Progress"}
                <img src='../assets/transfer.gif' style="height: 18px;"/>
            </g:else>
        </td>
        <td class="align-center" style="color:${myInstance?.objectColor}">${myInstance?.confidence?:"N/A"}</td>
    </tr>
</g:each>
</tbody>

Currently I've written that ${"Second Analytics"}<br>${"In-Progress"} here I require call to Controller action till I didn't receive any text for the same.

Thanks...


Solution

  • I have tried below code. Working fine for me.

    function fetchColumn2() {
      setInterval(loadColumn2, 3000,id);    
    }
    
    function loadColumn2(id){
    //Make ajax call and get response
    $.ajax({
            url:URL,//URL to action in controller
            data: {id:'1'},
            success: function(resp){
                console.log(resp.id);
                console.log(resp.column2);
                var column2Val = resp.column2;
                if(column2Val != ""){
                    //TODO: Set value to your table data
                    clearInterval(this);
                }                
            }
        });
    }