Link to home
Start Free TrialLog in
Avatar of Jeff
Jeff

asked on

How do I send a request (post or get) without leaving the page?

I am querying a MySQL database for events that need to be run on another server. When an event time comes up I need to send a request (either post or get) to the other server to start that event. There may be more than one event to be started at the same time. I need to check for events to be run up to 15 minutes prior to the event time.

Here is what I have so far:
// Check for events to be run
	$strSQL = "SELECT * from tblque WHERE EventDate = CURDATE() AND EventRun = '0' AND (EventTime >= CURTIME() AND EventTime <= ADDTIME(CURTIME(), '15:00'))";
//	echo $strSQL;
	$resultr = mysql_query($strSQL);
	while ($rowRun = mysql_fetch_array($resultr)) {
	
		if  (mysql_num_rows($resultr) > 0) {
			echo "RUN EVENT"; //HTTP request here
			
//			echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://test.php?action=edit&EventID=" . $rowRun['EventID'] . "\">";
			
		}
		else {
			echo "NO EVENTS";
		}
	}

Open in new window

Avatar of margajet24
margajet24
Flag of Singapore image

<\!--
function ajaxFunction(){
        var ajaxRequest;
       
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert(\"Your browser broke\!\");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                         var temp;
                         temp = ajaxRequest.responseText;
                        ‘ results from the page
                }
        }
        ajaxRequest.open(\"GET\", \"serverTime2.cgi?abc=2&def=3\", true);
                                                                 ‘ put here the php page youre trying to access passing also
                                                                    the values you want to pass
        ajaxRequest.send(null);
}
//-->
you can execute a script / somewhat like activate "submit" without leaving the page using AJAX

please see this..

http://www.w3schools.com/ajax/default.asp
Avatar of Jeff
Jeff

ASKER

Thanks for the quick response. I am an intermediate, at best, with php and can barely fumble my way through java, so you may need to hold my hand a bit.

The code you wrote, is that java? if so, how do I include it in the php code?

<?php 
if  (mysql_num_rows($resultr) > 0) {
// end PHP here
?>
 
<\!-- 
function ajaxFunction(){
        var ajaxRequest;
        
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert(\"Your browser broke\!\");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                         var temp;
                         temp = ajaxRequest.responseText;
                        ‘ results from the page
                }
        }
        ajaxRequest.open(\"GET\", \"serverTime2.cgi?abc=2&def=3\", true);
                                                                 ‘ put here the php page youre trying to access passing also
                                                                    the values you want to pass
        ajaxRequest.send(null); 
}
//-->
			
<?php			
// Start PHP here
}

Open in new window

it is a javascript..
treat it like a part of the html codes..

ex
<html>
<body>

<script type="text/javascript">
// java script

</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of Jeff
Jeff

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial