Solved

Run ajax every 5 secs

Posted on 2014-10-11
10
171 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 56

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
How our DevOps Teams Maximize Uptime

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

 
LVL 56

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 56

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pass foreach data in php into jquery ajax 10 49
jQuery on click requires double click 6 32
2012 SQL to JSON Select 5 31
JS to redirect to prev page 8 23
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 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)

749 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