Tuesday, 28 May 2013

How do i use setinterval in javascript to make the status of the Importing task?

How do i use setinterval in javascript to make the status of the Importing task?

In my project i'm using Setinterval to display the importing status of the excelsheet to database. ie., if excelsheet contains 100 records means my status message is , Row 1 0f 100 Rows Inserted Row 2 of 100 Rows Inserted..
But if the row contains any empty value means i need to get the error details and add that too in the status message. So It works with some issues.
My javascript function is as follows.
 function ImportFormSuccess(taskId) {
        endform();
    Tid = taskId;

            try {
                intervalId = setInterval(function () {
                    $.ajax(
                    {
                        type: "POST",
                        url: rootDir + "Import/Progress",
                        data: { id: Tid },
                        success: function (data) {

                            if (data.split(',').length > 1) {
                                ErrorMessage = ErrorMessage + data.split(',')[1] + "<br/>";
                                updateMonitor();
                            }
                            else {
                                Message = data;
                                updateStatus();
                            }
                        }
                    });
                }, 100);

            }
            catch (err) {
                txt = "Error Description" + err.Message + "</br>";
                txt += "Click Ok to Continue. . .";
                alert(txt);
            }

        function updateMonitor() {
            $('#monitors').attr("class", "");
            $("#monitors").html(Message + "<br/>" + ErrorMessage);
        }

        function updateStatus() {
            $('#status').attr("class", "");
            $("#status").html(Message);

        }
View Code is:
<div id="monitors" style="padding: 2px;width:500px;height:150px;overflow:auto;border:1px solid;></div>
If i run the project and start the import means, it displays the following:
Row 5 Insert Failed. Row Contains Empty Value
Row 5 Insert Failed. Row Contains Empty Value
Row 5 Insert Failed. Row Contains Empty Value
Row 5 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
But i need it to be printed only once.. ie.,
Row 5 Insert Failed. Row Contains Empty Value
Row 7 Insert Failed. Row Contains Empty Value
Row 10 Insert Failed. Row Contains Empty Value
Row 15 Insert Failed. Row Contains Empty Value
any help???

No comments:

Post a Comment