Link to home
Start Free TrialLog in
Avatar of arielbf
arielbfFlag for Israel

asked on

Run ajax every 5 secs

Hi,

I need to run a query every 5 secs from to start when window loads.
This should simulate a person to person negotiation.
Here is my script:

<script>
    $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tableHolder').load('negotiation1.asp',
               {seller:'<%=session("partner")%>'},
               function(){
           setTimeout(refreshTable, 5000);
        });
    }
</script>

the html later:
<div id="tableHolder">....</div>

negotiation1.asp is expecting "seller" parameter as POST query.
However the parameter is not working - I get the table without contents.
Any ideas?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

what do you want to ask javascript to send a server side variable (a session variable partner)?
read it directly from the server, don't send it as parameter
Avatar of arielbf

ASKER

It is working now in Chrome and Firefox
not in IE...
<script>
    $(function(){
      setInterval(refreshTable, 1000);
    });

    function refreshTable(){
        $.ajax({
            url: 'negotiation1.asp',
            data: {seller: '<%=session("partner")%>',
            type: 'POST',
            success: function(response) {
                $('#tableHolder').html(response);
            }
        });
</script>

Open in new window

SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arielbf

ASKER

The same problem - the script is working on Chrome and Firefox, not working on IE
Avatar of arielbf

ASKER

To be more specific - it seems that the "setInterval" is not working
Are there any errors?
setInterval is a javascript function going forever.

I tested my code on IE8 and it works perfectly - so somewhere in your code you have another problem that is causing it to fail on IE

What version of IE is this not working on
What version of JQuery are you using - if 2.x check the jquery.com site for compatibility with older versions of IE.
Avatar of arielbf

ASKER

Well I stripped it from anything else - and it still not working on IE (no problem in Chrome and Firefox)... Here is the current code:

mainpage.asp:
<!DOCTYPE html>

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script>
$(function(){
  setInterval(refreshTable, 1000);
});

function refreshTable(){
      $.ajax({
            url: 'negotiation4.asp',
            success: function(response) {
                  $('#tableHolder').html(response);
            }
      });
}
</script>
</head>

<body>
      <div id="tableHolder">Table will appear here....</div>
</body>
</html>

and here is the current negotiation4.asp:
<table border='1'>
            <tr>
                  <th>Time</th>
                  <th>From</th>
                  <th>to</th>
                  <th>Comment</th>
            </tr>
            <tr>
                  <td>1</td>
                  <td>2</td>
                  <td>3</td>
                  <td>4</td>
            </tr>
      </table>

I'm trying to add rows manually to the table in negotiation4.asp and upload it to the server.
Firefox and Chrome shows me the changes that I made without having to refresh the main page.
IE is not showing the changes - even when I'm refreshing the mainpage page manually.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arielbf

ASKER

It is working now :-)