开发者

how to post values in php on load (without having to click anything)

I want to send a variable from my php page to my jquery code. I know that I can do this using $_post and $_get, however as far as I know, they involve an action from the user, to trigger the "send" action. I am looking for away to send this as the page loads (so the use does not (have to) know that that is going on)

I found this, but it might be out of context or might not be what I am looking for, but the following does not work:

 $.post("demo.php", { name: "John", time: "2pm" } );

Just so that you know why I am asking, I have an array of images, and a calculation of the number of images the array has. I need to seed this value to jquery so that I can use it for various widths and so on.开发者_开发技巧.. The only what that I thought of doing this was to have the value on the html as a hidden element, but that is not right in terms of accessibility and google search.


It seems you trying to get some variables from the server side (php) to the client side (javascript). One solution would be to generate the javascript variables in your server side code.

e.g.

echo '<script type="text/javascript">';
echo 'var name = "' . $nameVar . '";';
echo '</script>';

This is just a demo. You should get the idea how this works.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜