?
Solved

Run ajax every 5 secs

Posted on 2014-10-11
10
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
LVL 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 1000 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 58

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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

801 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