dqrqp8492 2011-06-03 09:20
浏览 46
已采纳

可以将带有AJAX的jQuery变量传递给PHP页面和会话变量吗? [重复]

Possible Duplicate:
Passing javascript variable to PHP

Hi

I wonder if it's possible to pass a variable from a jQuery script to a PHP-page and put the variable into a session variable like this:

$_SESSION['mapZoomArea'] = (isset($_GET['mapza']) ? $_GET['mapza'] : "";

I'm not sure how to pass the variable and the url to the server? Preciate some help!

Thanks!

  • 写回答

4条回答 默认 最新

  • dougong5285 2011-06-03 09:24
    关注

    If you want a dedicated service specifically for writing this value into the session, you probably should make it a POST request (GET will work too, but GET requests should be for data retrieval, not for writing to the server).

    Therefore, simply create a new PHP page, let's say "storezoomarea.php", and have jQuery make an Ajax POST request to that page:

    $.ajax({url: "storezoomarea.php", type: "post", data: {"mapza": mapza}})
    

    Then, on the server side, you can retrieve it from the _POST variable:

    $_SESSION['mapZoomArea'] = (isset($_POST['mapza']) ? $_POST['mapza'] : "";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料