doumianfeng5065 2011-05-10 16:30 采纳率: 0%
浏览 5
已采纳

jQuery / PHP混淆了

I have the following jQuery function in my PHP:

echo ' 
function myFunction() {
    return $.ajax({
        type: "POST",
        url: "mypage.php",
        data: "name=John&location=Boston"
    });
}

$.when(myFunction()).then(function(data) {
     // handle data return
     someOtherFunction(data);

     // need to set "data" var into PHP SESSION


}, function(error) { 
     // handle ajax error.
});
';

After my AJAX does the majic it returns a value (data), which I pass into another function. In addition I need to be able to set that value into a PHP session: $_SESSION['project'][data] = data;

How do I do that? The switching between PHP and JS confuses me for some reason...

  • 写回答

3条回答 默认 最新

  • douyingbei1458 2011-05-10 16:37
    关注

    That's impossible since the JS is now on the client side. You can't set PHP variables directly.

    What you could do is set a cookie in JS using document.cookie, and then on the next page request PHP can get at it via $_COOKIE.

    You could also just set the $_SESSION variable inside mypage.php - that may be significantly easier, if they both share the same session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图