Query-string encoding of a Javascript Object

前端 未结 30 3620
渐次进展
渐次进展 2020-11-22 00:23

Do you know a fast and simple way to encode a Javascript Object into a string that I can pass via a GET Request?

No jQuery, no

30条回答
  •  我寻月下人不归
    2020-11-22 01:02

    jQuery has a function for this, jQuery.param(), if you're already using it you can use that: http://api.jquery.com/jquery.param/

    example:

    var params = { width:1680, height:1050 };
    var str = jQuery.param( params );
    

    str now contains width=1680&height=1050

提交回复
热议问题