65bit Posted March 31, 2009 Share Posted March 31, 2009 I'm trying to get my first AJAX action to work. I'd like to fire a .php script on the server to send an email and don't need any response sent back to the calling page. Maybe not too real world, but seems it should work? I plucked the mail portion for one of my pages where it's actually working, so don't think that's the issue. And, my js alert boxes are popping up in dowork(), so I know it's making it that far. I commented the last 2 lines of dowork() out, as it seems I don't need them for what I'm trying to do, but have tried it with them as well with the same results. send_mail.php sits in the same folder as the .js I'm new to php and web stuff as well, so unfortunately, my mis-understanding could be about anywhere. Here's my my .js file: var xmlHttp; function GetXmlHttpObject() { xmlHttp=null; if (window.XMLHttpRequest) { // code for all new browsers xmlHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE5 and IE6 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if (xmlHttp=null) { alert("Your browser does not support XMLHTTP."); } return xmlHttp; } function doWork() { httpObject = GetXmlHttpObject(); if (httpObject != null) { alert("xmlHttp has been set according to the browser type ..."); httpObject.open("GET", "send_mail.php", true); alert("after the http object calls the php script ... "); //httpObject.send(null); //httpObject.onreadystatechange = setOutput; } } and here's send_mail.php <? mail("jdoe@comcast.net", "Test Message From PHP Script", "AJAX has worked!!", "From: jdoe@comcast.net" . "\r\n"); ?> Any pointers are appreciated! Thanks Quote Link to comment Share on other sites More sharing options...
corbin Posted March 31, 2009 Share Posted March 31, 2009 httpObject.send(null); Is required to tell the object to fire off the request. Quote Link to comment Share on other sites More sharing options...
65bit Posted April 1, 2009 Author Share Posted April 1, 2009 It even looks logical after you point it out. Thanks very much, it now works like I was hoping it would. Pretty cool stuff. Quote Link to comment Share on other sites More sharing options...
65bit Posted April 1, 2009 Author Share Posted April 1, 2009 Interestingly, it only seems to send the email the first time the event happens. The alert boxes keep popping up, so doWork() is being called, but the .php won't send the email again after the first time unless I close the tab / browser and go back 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.