Convert JavaScript object into URI-encoded string

后端 未结 11 1428
庸人自扰
庸人自扰 2020-12-04 18:54

I got a JavaScript object which I would like to get x-www-form-urlencoded.

Something like $(\'#myform\').serialize() but for objects.

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 19:45

    You need to use JSON.stringify() to serialize the JSON/JavaScript object.

    It is natively available in almost all the modern browsers but you can include the below js which will add the required library incase it is not available.

    http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js

提交回复
热议问题