在Javascript(jQuery / AJAX)中使用$ _GET,$ _SERVER变量

所以,这是一个超级简单的jQuery / AJAX评论系统第一步。 第二步是PHP将数据插入数据库。 我需要页面/ $ _SERVER [‘变量’]的$ _GET [‘变量’]存储到数据库中。 我如何在jquery中获取这些内容。 我不能在PHP中说$spot = $_GET['spot'] or $url = $_SERVER['FILE_SCRIPTNAME'] 。 它不会捡起来。 我必须通过jQuery / AJAX发送。 我怎样才能做到这一点?

 $(document).ready(function() { $('#submit_comment').click(function() { var comment = $('#place_comment').val(); // Somewhere here set the $_GET['variable']; $.ajax({ type: 'POST', url: 'http://localhost/app/comment/comment.func.php', data: 'comment='+comment, success: function(data) { $('#replies').html(data); } }); }); }); 

如果我理解你正在尝试做什么,你可以尝试这样的东西在你的客户端javascript中使用服务器端的PHP变量。

 var comment = $('#place_comment').val(); var myVariable = ''; 

你不能这样做:javascript是客户端 ,PHP $ SERVER数组是服务器端