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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀