mort Posted June 10, 2008 Share Posted June 10, 2008 Hey all At work we are trying to build an enewsletter sender, with a slick AJAX realtime confirmation box. Anyways we have 2 AJAX containers, one that will refresh every 5 seconds, and display any new rows in the "sent" table, this bit works fine as we leave it going, manually enter some data into the table and it returns the new rows. The problem we are having is with the 2nd container. This will basically take the other table of contact emails, split them into batches (so not to kill the SMTP server), and when it has been sent put a row into the "sent" table that would then be reflected in the top AJAX container. What happens is, when we apply it to a huge list of emails (so it doesnt all happen instantly), it wont actually display any changes in the top AJAX container, until the second one has finished processing my logic behind this was that it would be ok if we used 2 AJAX scripts, as they both run independantley to each other, but that seems not to be the case and I cant figure out why any ideas? Quote Link to comment Share on other sites More sharing options...
xtopolis Posted June 11, 2008 Share Posted June 11, 2008 Do you have the AJAX XMLHttpRequest object being sent with the "true" flag for asynchronous sending/receiving? xHRO.open("GET", url, true); Are you using a different XMLHttpRequest object for each container? Quote Link to comment Share on other sites More sharing options...
mort Posted June 17, 2008 Author Share Posted June 17, 2008 yes its being sent with a true flag and ummm not sure on the top of my head about using a different XMLHttpRequest object for each container, why? which would be making it not work? not really an AJAX / JS person, am more PHP. I got the AJAX functions from a tutorial for basic AJAX script and have modified it to suit my needs. Quote Link to comment Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 If you only have one html request object, then each container will try to use the same object, causing you problems (if it even works). Its better to create a function that creates the html request object, then call that function each time a function is called from the container. Quote Link to comment Share on other sites More sharing options...
mort Posted June 18, 2008 Author Share Posted June 18, 2008 ok so using a function I found on digitalbonsai (multi XHR's) I THINK I have done what you say... HTML Request object function xhrRequest(type) { var xhrSend; if (!type) { type = 'text'; } if (window.ActiveXObject) { try { xhrSend = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xhrSend = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } else if (window.XMLHttpRequest) { xhrSend = new XMLHttpRequest(); if (xhrSend.overrideMimeType) { xhrSend.overrideMimeType('text/' + type); } } document.getElementById('testlog').innerHTML += new Date().getTime() + ' Sending xhr:' + xhrSend + '<br />'; return (xhrSend); } Then the 2 functions that will insert / select the database table. function mailCampaign(url, reqType) { if (!reqType) { reqType = "html"; } var xhrRec = xhrRequest(reqType); url +='&t=' + new Date().getTime(); xhrRec.open('GET', url, true); xhrRec.send(null); xhrRec.onreadystatechange = function() { if (xhrRec.readyState == 4 && xhrRec.status == 200) { var ajaxDisplay = document.getElementById('sendEmails'); ajaxDisplay.innerHTML = xhrRec.responseText; } }; } function sendProgress(url, reqType) { if (!reqType) { reqType = "html"; } var xhrRec = xhrRequest(reqType); url +='&t=' + new Date().getTime(); xhrRec.open('GET', url, true); xhrRec.send(null); xhrRec.onreadystatechange = function() { if (xhrRec.readyState == 4 && xhrRec.status == 200) { var ajaxDisplay = document.getElementById('sendProgress'); ajaxDisplay.innerHTML = xhrRec.responseText; } }; } Then onclick the go button, it runs this function, which in turn runs the other 2 function loadMulti(batch_id, total, mailgroups, ec_id) { mailCampaign('eshots/process_send.php?mailgroups=' + mailgroups + '&ecid=' + ec_id + '&batch_id=' + batch_id, '2'); var updater = 'eshots/process_progress.php?batch_id=' + batch_id + '&total=' + total; setInterval("sendProgress('"+updater+"', '1')", 1000); } Anyways after all that its still doing the same thing. It will run both scripts, firebug shows the activity. mailCampaign() is ran, the sendProgress() one goes every second, but it has activity indicators next to it until about 30 seconds after u run it, (when the mailCampaign() finishes). Then it displays the changes but all in one go instead of on the fly I have tested it so I only run the sendProgress script, add a line into the DB manually and it comes up as it should do, but the second I try to do the select AND insert scripts at the same time it starts being lame. Its deffo something to do with not liking running 2 requests, but as I said I am no JS dev and am still learning. Pls could someone help me out, have been trying to sort this for a while and its doing my head in!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.