weixin_33696822 2018-04-19 21:14 采纳率: 0%
浏览 32

序列化var(jquery)?

I have to use jquery serialize for this var... how to?

    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条回答 默认 最新

  • weixin_33739523 2018-04-19 21:35
    关注

    I assume by serialize you mean convert between string and object. Use the JSON object methods:

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

    </div>
    
    评论

报告相同问题?