Solved

Run ajax every 5 secs

Posted on 2014-10-11
10
167 Views
Last Modified: 2014-10-12
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?
0
Comment
Question by:arielbf
  • 5
  • 3
  • 2
10 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40374692
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
0
 

Author Comment

by:arielbf
ID: 40374718
It is working now in Chrome and Firefox
not in IE...
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 40374722
<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

0
 
LVL 52

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 40374727
Correction - missing }
$(function(){
  setInterval(refreshTable, 1000);
});

function refreshTable(){
	$.ajax({
		url: 'negotiation1.asp',
		data: {seller: '1'},
		type: 'POST',
		success: function(response) {
			$('#tableHolder').html(response);
		}
	});
}

Open in new window

0
 

Author Comment

by:arielbf
ID: 40375031
The same problem - the script is working on Chrome and Firefox, not working on IE
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:arielbf
ID: 40375035
To be more specific - it seems that the "setInterval" is not working
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 40375433
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.
0
 

Author Comment

by:arielbf
ID: 40375711
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.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 40375718
replace :
 url: 'negotiation4.asp',
by :
 url: 'negotiation4.asp?t=' + new Date().getTime(),
0
 

Author Closing Comment

by:arielbf
ID: 40375754
It is working now :-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now