开发者

PHP and JS test

I need to test a value in the client side, using js, before the content is loaded. Then, I want to give this valu开发者_StackOverflow社区e to PHP, which then should show the appropriate content depending on the value. The way I am doing it, is by posting via $.post of jquery, obtaining the value with a PHP function, storing it in $_SESSION and displaying the appropriate content.

However, since I am using $_SESSION, if the client side value changes, it requires two refreshes to show the correct content (because it looks like when jQuery is posting, it keeps loading the content and the new $_SESSION value is already late).

Should I use $_SESSION? Is there a better way to do this?

Thanks!!!


Simply use $.get of jquery and request the page with variables passed to it using traditional GET method.

Javascript side:

fetch "./data.php?param1=value1&param2=value2"

PHP Side:

$param1=$_GET['param1'];
$param2=$_GET['param2'];
use it and compile the html.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜