Solved

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

Posted on 2008-06-25
6
410 Views
Last Modified: 2013-12-12
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

0
Comment
Question by:Jeff
[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
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:margajet24
ID: 21871751
<\!--
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);
}
//-->
0
 
LVL 10

Expert Comment

by:margajet24
ID: 21871763
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
0
 

Author Comment

by:Jeff
ID: 21878877
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

0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 10

Expert Comment

by:margajet24
ID: 21879877
it is a javascript..
0
 
LVL 10

Expert Comment

by:margajet24
ID: 21879952
treat it like a part of the html codes..

ex
<html>
<body>

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

</script>
</body>
</html>
0
 

Accepted Solution

by:
Jeff earned 0 total points
ID: 21888110
Thanks for the help, margajet24. I found the exact solution here:
http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html

<?php
 
 $ch = curl_init('http://www.mysite.com/index.php?option=com_content&task=blogcategory&id=24&Itemid=55');
 curl_exec ($ch);
 curl_close ($ch);
 
?>

Open in new window

0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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