dougai3418
2011-09-20 19:19
浏览 48
已采纳

如何将一个变量从一个php传递给另一个由ajax调用的变量,而不会让前端看到它

I have a php function that's run when a build.php page is loaded and creates a $variable. I have save.php also, which is called via an ajax function in scripts.js (taking data sent through POST), but I need to use $variable in save.php.

Is there a good way to send further data through ajax without it being visible on the front end?

I thought of using a $_SESSION variable for this, which seems like it would work, but I understand it may not be totally reliable and is not always a good idea (though this might have been overstated where I was looking).

Is that the best way? Or is there some other way to get a PHP variable to another one via javascript without it being in the front end code?

图片转代码服务由CSDN问答提供 功能建议

我有一个php函数,它在加载build.php页面时运行并创建一个$ variable。 我也有save.php,它通过scripts.js中的ajax函数调用(通过POST发送数据),但是我需要在save.php中使用$ variable。

是 有没有一种很好的方法可以通过ajax发送更多的数据,而不会在前端看到它?

我想为此使用$ _SESSION变量,这似乎可以工作,但我 了解它可能不完全可靠并且并不总是一个好主意(虽然这可能被夸大了其中 我在寻找)。

这是最好的方法吗? 或者是否有其他方法通过javascript将PHP变量传递给另一个,而不是在前端代码中?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题