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 求计算赫斯特(Hurst)指数
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大