Solved

Run ajax every 5 secs

Posted on 2014-10-11
10
170 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 55

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 55

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
 

Author Comment

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery Validation Messages Not Showing Up 3 20
Diminish Pop-up  in 3 seconds 7 44
Weighted Randomizing 6 29
Responsive Font Size 6 24
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

792 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