简体   繁体   English

如何将ajax结果存储在php变量中?

[英]How to store ajax result in php variable?

<?php $shoppingcart = $jcart->display_cart(); ?>

<?php echo $shoppingcart; ?>

How can i store the ajax result(HTML code) in the php variable so i can save the HTML code in databases and display the result again? 如何将ajax结果(HTML代码)存储在php变量中,以便可以将HTML代码保存在数据库中并再次显示结果?

Please Help. 请帮忙。 thank you 谢谢

The ajax data comes often through GET or POST. Ajax数据通常来自GET或POST。 PHP stores those on global $_GET and $_POST variables, respectively. PHP将它们分别存储在全局$_GET$_POST变量中。

For instace, when accessing an URL like ' http://localhost:8080/?key1=value1&key2=value2 ', PHP will fill the $_GET reserved variable with the following array: 对于instace,当访问诸如' http:// localhost:8080 /?key1 = value1&key2 = value2 '之类的URL时,PHP将使用以下数组填充$ _GET保留变量:

[ 'key1' => 'value1', 'key2' => 'value2' ].

Refer to http://php.net/manual/en/reserved.variables.get.php and http://php.net/manual/en/reserved.variables.post.php for more information about those reseved variables. 请参阅http://php.net/manual/en/reserved.variables.get.phphttp://php.net/manual/en/reserved.variables.post.php ,以获取有关这些保留的变量的更多信息。

I would recommend you use a sessions and cookies to store the results. 我建议您使用会话和cookie来存储结果。 You can archive this by using javascript or a jquery plugin jquery cookie https://github.com/carhartl/jquery-cookie 您可以使用javascript或jquery插件jquery cookie https://github.com/carhartl/jquery-cookie对其进行存档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM