Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Javascript发布到PHP,然后在另一个Javascript中检索_Javascript_Php_Ajax - Fatal编程技术网

将Javascript发布到PHP,然后在另一个Javascript中检索

将Javascript发布到PHP,然后在另一个Javascript中检索,javascript,php,ajax,Javascript,Php,Ajax,我试图将java_post.js中的值发布到php_post.php中,然后在另一个javascript页面index.html中检索。到目前为止,我可以将该值发布到php_post.php中,并作为alertdata检索回我的java_post.js中 但我无法从index.html中检索 Java_post.js var url_link ="index.html"; //On Click Select Function $("#table_hot").on('click', 'tbod

我试图将java_post.js中的值发布到php_post.php中,然后在另一个javascript页面index.html中检索。到目前为止,我可以将该值发布到php_post.php中,并作为alertdata检索回我的java_post.js中 但我无法从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");
}
当客户端单击所选表,然后将其发布到php_post.php中时,将检索该值。php_post.php将过滤结果并返回index.html

因此,现在我可以检索该值并将其作为java_post.js的警报发布到中,但该值不是传递到index.html,并且我收到了未定义的postvalue的错误


所以我现在的问题是,有没有任何方法可以让我从php_post.php在index.html中显示值。作为提醒,java_post.js中的alertdata只是一个测试目的,用于显示从php_post.php返回的值,您可以在php_post.php中将所需的值设置到php会话中。
通过这种方式,您可以在任何需要的页面上检索会话的值。

您遇到的问题是,当您将数据传递到PHP文件并在JavaScript中接收数据时,该信息只会持续到您当前请求的时间

为了解决这个问题,考虑使用PHP会话变量来存储数据,以便以后可以检索。 例如:

// php_post.php
<?php

start_session();   // initializes session for persistent data

$filtered_students = array_filter($ARRAY, function($row) {

$hotspot_value = $_POST['postvalue'];
     if($row['name'] == $hotspot_value){
         return true;
     }
});

$_SESSION["filtered_students"] = $filtered_students;   // You can now retrieve this in
                                                       // Another PHP file
?> 
现在,在另一个文件中,您可以将HTML文件切换为从php_get.php获取:

//php_get.php
<?php

start_session();          // Don't forget to start the session

echo $_SESSION['filtered_students'];

?>
更多信息请点击此处:

// php_post.php
<?php

start_session();   // initializes session for persistent data

$filtered_students = array_filter($ARRAY, function($row) {

$hotspot_value = $_POST['postvalue'];
     if($row['name'] == $hotspot_value){
         return true;
     }
});

$_SESSION["filtered_students"] = $filtered_students;   // You can now retrieve this in
                                                       // Another PHP file
?> 
//php_get.php
<?php

start_session();          // Don't forget to start the session

echo $_SESSION['filtered_students'];

?>