[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,
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?
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?
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.
Re: [RESOLVED] [AJAX/Javascript & PHP] Send Form using POST Method to a PHP page.
Awesome!!!
Thanks for my responses and everything were resolved. :lol: