ho fatto ulteriori test ma la situazione non è cambiata, inoltre ho consultato l'error.log di apache per capire bene cosa accade quando il file invia.php viene richiamato, ed infatti mi ritorna un errore:
PHP Notice: Undefined index: messagetext in C:\\Inetpub\\wwwroot\\php\\message\\invia.php on line 11, referer: http://localhost/message/testtextarea.php
non capisco perchè non trovi il riferimento a messagetext.. per completezza riposto i files leggermente modificati per le prove.
l'id è indicato nel file testtextarea.php con
<textarea cols="30" rows="4" id="messagetext"></textarea>
mentre il valore viene recuperato in textarea.js con
var params = document.getElementById("messagetext").value;
nell'invia.php invece ho
$message = $_POST["messagetext"];
testtextarea.php :
codice:
<?php
session_start();
?>
<html>
<head>
<script type="text/javascript" src="textarea.js"></script>
</head>
<body>
<textarea cols="30" rows="4" id="messagetext"></textarea>
invia
</body>
</html>
textarea.js :
codice:
// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
{
// will store the reference to the XMLHttpRequest object
var xmlHttp;
// this should work for all browsers except IE6 and older
try
{
// try to create XMLHttpRequest object
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// assume IE6 or older
var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP");
// try every prog id until one works
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
{
try
{
// try to create XMLHttpRequest object
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
}
catch (e) {} // ignore potential error
}
}
// return the created object or display an error message
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else
return xmlHttp;
}
// make asynchronous HTTP request using the XMLHttpRequest object
function process()
{
// proceed only if the xmlHttp object isn't busy
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
// retrieve the name typed by the user on the form
var params = document.getElementById("messagetext").value;
xmlHttp.open("POST", "http://localhost/message/invia.php", true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(params);
}
else
// if the connection is busy, try again after one second
setTimeout('process()', 1000);
}
// executed automatically when a message is received from the server
function handleServerResponse()
{
// move forward only if the transaction has completed
if (xmlHttp.readyState == 4)
{
// status of 200 indicates the transaction completed successfully
if (xmlHttp.status == 200)
{
//DO NOTHING
}
// a HTTP status different than 200 signals an error
else
{
alert("There was a problem accessing the server: " + xmlHttp.statusText);
}
}
}
invia.php :
codice:
<?php
session_start();
require("db_config.php");
header('Expires: Wed, 23 Dec 1980 00:30:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
$message = $_POST["messagetext"];
$dayOfWeek = date("l - d-m-Y - H:i:s");
$query = "INSERT INTO messages (post_id, user_id, content, created)
VALUES ('23', '1', '" . $message . "', '" . $dayOfWeek . "')";
pg_query($query);
?>