序列化var(jquery)?

时间:2018-04-19 21:14:24

标签: php jquery ajax serialization

我必须为这个var使用jquery serialize ...如何?

    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);
   }});

1 个答案:

答案 0 :(得分:0)

我假设通过序列化你的意思是在字符串和对象之间进行转换。使用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) );