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条)

报告相同问题?