【问题标题】:Serialize a var (jquery)?序列化一个var(jquery)?
【发布时间】:2018-09-30 12:06:23
【问题描述】:

我必须为这个变量使用 jquery 序列化...如何?

    var type = { op:"add" , id_user : <?=$u->id?> , tipo : tipo , description : $("#desc_new_param").val() }
                    $.ajax({type: "POST",cache: false,url: "<?=SYSTEM_WEB_ADMIN?>second.php",data: type,success: function(data) {
                        $("#tab-"+tipo).html(data);
   }});

【问题讨论】:

  • 序列化是指把它变成一个字符串吗?
  • 所以嗯:var str = type.serialize();?

标签: php jquery ajax serialization


【解决方案1】:

我假设序列化是指在字符串和对象之间进行转换。使用 JSON 对象方法:

var type = { 
    op:"add" , 
    id_user : 1431 , 
    tipo : "tipo something" , 
    description : "some sort of description" 
};

var myTypeString = JSON.stringify(type);

console.log("myTypeString is a "+typeof(myTypeString), myTypeString);

console.log("As a JSON object: ", JSON.parse(myTypeString) );

【讨论】:

    猜你喜欢
    • 2011-05-13
    • 2016-10-02
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    相关资源
    最近更新 更多