JS + PHP (JS function results to PHP variable)?

blargh

New member
Basically, I'm trying to use AJAX to take the results of a JS script that has different results for ever visitor, and pushes it back into php, where I make it a variable and write it to an internal file.

Here is my main code, with the function script taken out.


<form name="inputform">
<input name="line" value="line">

<script language="javascript">
function thefunction() {
...
...
...
...
}
</script>
</input>
</form>

var http = new XMLHttpRequest();
var url = "ProcessingPage.php";
var params = "value1=" + new Date().getTime();
http.open("POST", url, true);

http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length"... params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = thefunction() {
if(http.readyState == 4 && http.status == 200) {
// this is notification of the php processing result - you would probably deal with that with xml
document.getElementById("notification"... = http.responseText;
}
}
http.send(params);
<?
$result = $_POST['line'];
$ip = $_SERVER['REMOTE_ADDR'];
$fp = fopen('file.txt', 'a');
fwrite($fp, $result);
fclose($fp);

} else {
echo "Script Failed";
}
?>


So let's say the result to the JS script was like:
your main password is: hampster12
your second main password is: dogs456
...etc.

I want those lines to be sent into a php script so:
$variable = "your main password is: hampster12 < br />
your second main password is: dogs456 < br />"


For the life of me, I spent the last couple days mindlessly trying to figure this out. I can't. :\

Wondering if anyone could help me figure out how to write an AJAX script to take the custom JS script results, and push them into a php script, even though php runs before JS.
 
What you're asking isn't possible.

All AJAX calls always initiate a SECOND call - the first being the one that loads the page.

Sorry!

You need to find a way of transferring the data that needs to be processed from the first to the second call, through session data, a file or a database.
 
What you're asking isn't possible.

All AJAX calls always initiate a SECOND call - the first being the one that loads the page.

Sorry!

You need to find a way of transferring the data that needs to be processed from the first to the second call, through session data, a file or a database.
 
Back
Top