Jadager
Jadager

Reputation: 69

Ajax being called twice on setInterval

I'm doing ajax calls in a specific time interval using javascript setInterval function however the ajax code is being executed twice, so I'm getting the same response twice and I have no idea why this is happening, here's the code:

        setInterval(function () {ajaxCall();},15000);

        function ajaxCall(){
            var uri = "url here";
            $.ajax({
            type: "GET",
            url: uri,
            dataType: "jsonp",
            success: function(response){
                    console.log(response);
                    var txt = $("#textarea");
                    txt.val( txt.val() + response.user + " (" + response.time + ") > " 
                    + response.text + '\n');
                    }
            });
        }

Any help would be appreciated.

Thanks

Upvotes: 3

Views: 1271

Answers (1)

Jadager
Jadager

Reputation: 69

Ok so I just figured it out, I had that script inside the html body tag but if I move it inside head tags it stops calling it twice, not sure why this is but it solved the problem. Sorry for wasting your time for something that simple xD

Upvotes: 1

Related Questions