-
How to refresh javascript variables before ajax sends data.
Hi Guys,
I've been up all night with this one. I have a javascript which reads from my system whether I'm on my voip or not - something I'm proud of. I wanted to have this update a mysql database every 2 seconds so have got this so far:
<?
header("Cache-Control: post-check=1,pre-check=2");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$time=rand(1000,100000);
?>
<SCRIPT type="text/javascript">
var CLMgr = new ActiveXObject("CLMgr.ClientLineMgr");
var oline = CLMgr.DispSelectedLine;
var warthog = oline.DispIsOutgoingCall;
var szNumber = oline.DispPeerNumber;
var hold = "../../Modules/Lab/data_feed_process.php?time=<?=$time;?>&tel=";
var page = hold + szNumber;
function ajax(url,target)
{
//native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
//IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ajaxDone
(target);};
req.open("GET", url, true);
req.send();
}
}
setTimeout("ajax(page,szNumber,oline,CLMgr,'scriptoutput')", 2000);
}
function ajaxDone(target) {
//only if req is "loaded"
if (req.readyState == 4) {
//only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
} else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText; } }}
</script>
<body onLoad="ajax(page,szNumber,oline,CLMgr,'scriptoutput')">
<span id="scriptoutput"></span>
Basically var page ends up carrying the phone number I'm connected to to the data_feed_process.php page which updates the database. This works great however the data actually sent doesn't actually change regardless of whether I disconnect the phone, until I press refresh. So if I make a call and load the page, every two seconds the database updates the fact that I'm on the phone.
I somehow need the variables that get the phone number to refresh at the same time javascript times out the above, as you'll see I've added the variables to the timeout and onload areas with no joy at all. Just to note unfortunatley the phone nubmer can only be gained client side ie via javascript.
If anyone can help I would really appreciate it, I need some sleep!
Similar Threads
-
Replies: 0
Last Post: 08-10-2007, 07:17 PM
-
By kamisetty in forum XML
Replies: 4
Last Post: 02-08-2002, 11:14 AM
-
By Tim Frost in forum xml.announcements
Replies: 0
Last Post: 04-02-2001, 10:53 AM
-
By sflee in forum VB Classic
Replies: 0
Last Post: 07-15-2000, 12:17 AM
-
By Patrick Spence in forum Web
Replies: 1
Last Post: 03-30-2000, 08:02 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|