Results 1 to 4 of 4

Thread: Retrieve the response with POST

  1. #1
    Join Date
    Jun 2009
    Posts
    83

    Retrieve the response with POST

    I got this snippet on the net and I adapted to my needs. We must recognize this is my 1st time I have used AJAX. After running this code, it gives me all the php code but not the desired message:

    Code:
    function getXhr(){
    			var xhr = null;
    			if(window.XMLHttpRequest) // Firefox and other
    				xhr = new XMLHttpRequest();
    			else if(window.ActiveXObject){ // Internet Explorer
    				try {
    						xhr = new ActiveXObject("Msxml2.XMLHTTP");
    					} 
    				catch (e) {
    						xhr = new ActiveXObject("Microsoft.XMLHTTP");
    					}
    			}
    			else { 
    				alert("Your browser does not support XMLHTTPRequest Objects ...");
    				xhr = false;
    			}
    			return xhr
    		}
     
    		function go(ip){
    			if(ip !=""){
    										
    				var xhr = getXhr()
    				xhr.onreadystatechange = function(){
    					if(xhr.readyState == 4 && xhr.status == 200){
    						document.ordi_enr.dysfon.value = xhr.responseText;
    					}
    				}
    				xhr.open("POST","load_dysfon.php",true);
    				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    				xhr.send(null);
    			}else { document.ordi_enr.dysfon.value = "";}
    		}
    PHP Code:
    <?
        
    echo "Everything works";
    ?>

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Retrieve the response with POST

    You have not mentioned the keyword "PHP" in your code. It should be like this:

    PHP Code:
    <?php
        
    echo "Everything works";
    ?>

  3. #3
    Join Date
    Jun 2009
    Posts
    83

    Re: Retrieve the response with POST

    Thank you, that is a mistake on my part. But even after changing the error and after modifying the message instruction on php echo the old message still appears. Another thing, I use smarty. But I have a new problem is to select my data from the database from a test.

    HTML Code:
    {literal}
    	<script language='javascript'>
    function add_tache(){
    			var value = this.ordi_enr.lst_tache.options[this.ordi_enr.lst_tache.selectedIndex].value;
    			var text = this.ordi_enr.lst_tache.options[this.ordi_enr.lst_tache.selectedIndex].text;
    			document.forms.ordi_enr.tache_eff.options[document.forms.ordi_enr.tache_eff.options.length] = new Option(text,value);
    			this.ordi_enr.lst_tache.options[this.ordi_enr.lst_tache.selectedIndex] = null;			
    		}	
    		
    		function drop_tache(){
    			var value = this.ordi_enr.tache_eff.options[this.ordi_enr.tache_eff.selectedIndex].value;
    			var text = this.ordi_enr.tache_eff.options[this.ordi_enr.tache_eff.selectedIndex].text;
    			document.forms.ordi_enr.lst_tache.options[document.forms.ordi_enr.lst_tache.options.length] = new Option(text,value);
    			this.ordi_enr.tache_eff.options[this.ordi_enr.tache_eff.selectedIndex] = null;
    		}
    		
    		function getXhr(){
    			var xhr = null;
    			if(window.XMLHttpRequest) 
    				xhr = new XMLHttpRequest();
    			else if(window.ActiveXObject){ 
    				try {
    						xhr = new ActiveXObject("Msxml2.XMLHTTP");
    					} catch (e) {
    						xhr = new ActiveXObject("Microsoft.XMLHTTP");
    					}
    			}
    			else { 
    				alert("Your browser does not support XMLHTTPRequest objects...");
    				xhr = false;
    			}
    			return xhr
    		}
     
    		function go(ip){
    			if(ip != ""){
    				var val_ip = document.getElementById('ip_ordi').value;
    				var xhr = getXhr()
    				xhr.onreadystatechange = function(){
    					if(xhr.readyState == 4 && xhr.status == 200){
    						document.ordi_enr.dysfon.value = xhr.responseText;
    				}
    			}
    			xhr.open("POST","load_dysfon.php",true);
    			var data = escape(document.getElementById('ip_ordi').value);
    			xhr.send(data);
    		}else { document.ordi_enr.dysfon.value = "";}
    		}
    		
    	</script>
    {/literal}
    <form name="ordi_enr" action="inter_add.php" method="post" onsubmit="return verif_form();">
    					<fieldset><legend><h4><span class="style1"><em>Intervention</em></span></h4></legend>
    						<p align="center"><label for="ip_ordi">IP : </label>
    							<select name="ip_ordi" onchange="go(this.value)">
    								<option value=""></option>
    								{section name=idx loop=$list_ip}
    									<option value="{$list_ip[idx].ip_ordin}">{$list_ip[idx].ip_ordin}</option>
    								{/section}
    							</select>
    							
    						<label for="dysfon">Dysfonctionnement:</label>
    						<textarea name="dysfon" cols="60" readonly="true"></textarea></p>	
    						
    						<p align="center"><label for="lst_tache">List of tasks(s):</label>
    						<select name="lst_tache" size="5" style="width:255px" onchange="add_tache();">
    							{section name=idx loop=$lst_tache}
    								<option value="{$lst_tache[idx].num_tach}">{$lst_tache[idx].lb_tache}</option>
    							{/section}
    						</select>
    						
    						<label for="tache_eff">Task(s) effect(s):</label>
    						<select name="tache_eff" size="5" style="width:255px" onchange="drop_tache();">
    							
    						</select></p>
    												
    					</fieldset>
    					<p align="center">
    					  <input name="submit" type="submit" value="Save info." />
    					</p>
    				</form>
    The content of load_dysfon.php
    PHP Code:
    <?php
        header
    ("Cache-Control: no-cache, must-revalidate");
        
    header('Content-type: text/html; charset=iso-8859-1'); 
        require_once(
    'config.inc.php');
        
        
    $select_dysf mysql_query("SELECT num_dysf,ip_ordin,dte_day,dysfo_or FROM tb_dysfon WHERE ip_ordin'".$_POST['data']."'");
        while (
    $row mysql_fetch_row($select_dysf))
        {
            echo 
    $row[3]; 
        }    
    ?>
    By checking the value of $ _POST [ 'data'], it is empty.

  4. #4
    Join Date
    May 2008
    Posts
    685

    Re: Retrieve the response with POST

    var data = escape(document.getElementById('ip_ordi').value);
    xhr.send(data);
    Code:
    var data = "data="+escape(document.getElementById('ip_ordi').value);
    			xhr.send(data);

Similar Threads

  1. Replies: 1
    Last Post: 26-01-2012, 12:27 AM
  2. How many post are allowed to post on a blog in a single day
    By umaymah in forum Technology & Internet
    Replies: 3
    Last Post: 16-01-2011, 06:11 AM
  3. How to retrieve Response from HTML and PHP pages
    By Sachit in forum Software Development
    Replies: 2
    Last Post: 02-02-2009, 12:11 PM
  4. Ping 192.168.1.101 but the response is 192.168.1.107
    By Daigle in forum Windows Vista Network
    Replies: 1
    Last Post: 04-11-2008, 07:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,927,475.71791 seconds with 17 queries