dtnbjjq51949 2011-06-02 18:59 采纳率: 0%
浏览 47
已采纳

将30个变量从客户端发布到服务器的最佳方法是什么?

hey, i have about 30 variables which are created and modified by user (none of which comes from input, so submitting a form is not really an option), once modification finished a JS function process the variables and spouse to post them to the controller which will then send the to the model.

now, as appears in the title, my question is what is the best way for me to send them?

thnx for time and attention, Ido

  • 写回答

5条回答 默认 最新

  • dpfqy5976 2011-06-02 19:08
    关注

    Modern browsers and newer versions of PHP both support JSON, and there are supporting libraries you can use if the browsers you need to support or the PHP version you're stuck with are old. I'd recommend this as a way of getting data back and forth.

    Client side JS:

    var myobject = {
      userparam: "value",
      anotherThing: "another value",
      something: "etc"
    }
    
    var serialized = JSON.stringify(myobject);
    
    // use any AJAX technicque to POST 'serialized' back to the server
    

    Then on the server-side:

    <?php
    
      $myobject = json_decode( $_POST['serialized'], true );
    
      $myobject['userparam'] == "value"; // true
    

    Hope this helps!

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

报告相同问题?