Results 1 to 5 of 5

Thread: [RESOLVED] [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.

  1. #1

    Thread Starter
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Resolved [RESOLVED] [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.

    Please give me a very simple working example.

    I'm totally a newbie in PHP & AJAX.


    Thanks,

  2. #2

    Thread Starter
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Exclamation Re: [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.

    I'm trying to do this one but still not successful.

    This is the page:
    Code:
    <body>
    <script type="text/javascript">
    function ajaxFunction()
      {  var xmlHttp;
      try
        {    // Firefox, Opera 8.0+, Safari    
    	xmlHttp=new XMLHttpRequest();    
    	}
      catch (e)
        {    // Internet Explorer    
    	try
          {      
    	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
    	  }
        catch (e)
          {      
    	  try
            {        
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
    		}
          catch (e)
            {        alert("Your browser does not support AJAX!");        
    		return false;
    		}
    	  }    
       }
        
      	var params = "Name="+document.MyForm.Name.value;
        xmlHttp.open("GET","welcome.php",true);
    	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    	xmlHttp.setRequestHeader("Content-length", params.length);
    	xmlHttp.setRequestHeader("Connection", "close");
    	xmlHttp.onreadystatechange=function()
          {
          if(xmlHttp.readyState==4 && xmlHttp.status == 200)
            {
            alert(xmlHttp.responseText);//document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
            }
          }
        xmlHttp.send(params);  
    	}
    	</script>
    	<form action="javascript:ajaxFunction();" method="POST" enctype="application/x-www-form-urlencoded" name="MyForm">
    		<input type="text" name="Name"/>
    		<input type="submit"/>
    	</form>
    	<div id="divContents">	
    	</div>
    </body>
    And the welcome.php:
    PHP Code:
    Good day <?php echo $_POST["Name"]; return 0;?>.
    What should I do?

  3. #3

    Thread Starter
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Re: [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.

    Oh my, I found what is wrong.
    xmlHttp.open("GET","welcome.php",true);
    It GET should be POST.

    But I always see this error message at the last line: "Error in my_thread_global_end():1 threads didn't exit".

    How to solve this?

  4. #4

    Thread Starter
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Re: [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.

    There's a a bug with libmysql.dll in PHP 5.2.2.
    To resolve this, the libmysql.dll must be replaced by the one from PHP 5.2.1.

  5. #5

    Thread Starter
    Fanatic Member eSPiYa's Avatar
    Join Date
    Jun 2006
    Location
    in our house
    Posts
    751

    Re: [RESOLVED] [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.

    Awesome!!!
    Thanks for my responses and everything were resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width