0

I'm trying to fetch user details from a php and updating the div inside the modal with the result.

My problem is I'm getting the result very late. it takes around 10 minutes to update the result. I could not figure out how to resolve this. Meanwhile I've googled for a fix, but unfortunate none of the solutions fix my problem.

My JS

setInterval(function(){
        fetch_program(); //UPDATE
        fetch_user();
    }, 1000);

function fetch_user()
        {
            var action = "fetch_user_data";
            var id = $('#userid').val();

            $.ajax({
                url:"users.php",
                method:"POST",
                data:{id:id, action:action},
                success:function(data)
                {
                    $('#userslist').html(data);
                }
            })
        }

My users.php

if($_POST["action"] == "fetch_user_data")
{
    //sample post for testing
    echo $_POST["id"];

}

The result from the ajax in set inside modal. Please suggest any possible fix

UPDATE:

I have a programe list which is populated by ajax. screenshot below programme list

you can see that there are 2 button add user and delete When I click the add user, it open in a modal with a multiple select. The add user button is done onclick event which will call a function below

function adduser(userid)
    {
        var userid  = userid;
        $("#usermodal").modal("show");
        $('#userselect').data("task",userid);
        $('#userid').val(userid);
    }

In this modal I'm using fetch_user() ajax function to populate the users.

So is this delay caused by any of these function?

theveil
  • 77
  • 1
  • 15
  • this might not be related to the code, maybe its related to the **network issue** or the database, can you elaborate about the database schema and if its using indexing for user table, try to debug the query result and how much it take can help also. – ROOT Feb 02 '20 at 11:14
  • but I'm using a couple of other ajax and that gives quick results – theveil Feb 02 '20 at 11:15
  • ok can you remove the setInterval? or replace it with setTimeout function, I just noticed that you are using `setInterval()` call. just for testing I think it might be the issue. – ROOT Feb 02 '20 at 11:19
  • You need to clear your interval. may be this link will help https://stackoverflow.com/questions/16437173/stop-setinterval/16437215 – alithedeveloper Feb 02 '20 at 11:20
  • Sorry, It doesn't work. I cleared the interval, still its being delayed. – theveil Feb 02 '20 at 11:34
  • is there any way to find where the delay is – theveil Feb 02 '20 at 11:59

0 Answers0