I m trying to post the value from my java_post.js
into php_post.php
and then retrieve in another javascript page, index.html. So far i can post the value into the php_post.php
and retrieve back into my java_post.js
as alert(data)
but i cannot retrieve from my index.html
Java_post.js
var url_link ="index.html";
//On Click Select Function
$("#table_hot").on('click', 'tbody tr',function(){
$(this).addClass('selected').siblings().removeClass('selected');
var value=$(this).find('td:first').html();
$.post('PHP_post/php_post.php',
{
postvalue:value
},
function(data){
alert(data);
}
);
});
//Window Pop Out Function
function hotspot_pop(url_link){
newwindow = window.open(url_link, '', "status=yes,
height=500; width=500; resizeable=no");
}
The value is retrieve when the client click the selected table and then post into the php_post.php
. The php_post.php
will filter the result and return to index.html
.
$filtered_students = array_filter($ARRAY, function($row) {
$hotspot_value = $_POST['postvalue'];
if($row['name'] == $hotspot_value){
return true;
}
});
echo $filtered_students;
So now i m able to retrieve the value and post into as an alert for my java_post.js
but the value is no pass into index.html
and i receive the error for undefined postvalue
.
<html>
<script src="js/jquery-1.11.1.min.js"></script>
<body>
<div id="result"></div>
<script>
var xmlhttp_user = new XMLHttpRequest();
var url_user = "PHP_post/php_post.php";
xmlhttp_user.onreadystatechange=function() {
if (xmlhttp_user.readyState == 4 && xmlhttp_user.status == 200) {
document.getElementById("result").innerHTML=xmlhttp_user.responseText; }
}
xmlhttp_user.open("GET", url_user, true);
xmlhttp_user.send();
</script>
</body>
</html>
So my problem is now, is there any method that allow me to show the value in index.html
from php_post.php
. As a reminder the alert(data)
from java_post.js
is just a testing purpose to show the value did post and return from php_post.php
leedotpang :
The issue you're having is that when you pass the data into your PHP file and receive the data back in your JavaScript, the information only lasts as long as your current request.\n\nTo fix this issue, consider using PHP Session variables to store your data, so that you can retrieve it later.\n\nExample:\n\n// php_post.php\n<?php\n\nstart_session(); // initializes session for persistent data\n\n$filtered_students = array_filter($ARRAY, function($row) {\n\n$hotspot_value = $_POST['postvalue'];\n if($row['name'] == $hotspot_value){\n return true;\n }\n});\n\n$_SESSION[\"filtered_students\"] = $filtered_students; // You can now retrieve this in\n // Another PHP file\n?> \n\n\nNow in another file (you would switch your HTML file to get from php_get.php):\n\n//php_get.php\n<?php\n\nstart_session(); // Don't forget to start the session\n\necho $_SESSION['filtered_students'];\n\n?>\n\n\nMore information here: http://www.w3schools.com/php/php_sessions.asp",
2015-01-30T04:13:46