jquery build http query string

前端 未结 2 1224
感情败类
感情败类 2021-02-05 02:47

I have an object like this:

Object
    id: \"myid\"
    token: \"sometoken\"

I need to build a HTTP query-string and get something like this:

2条回答
  •  野性不改
    2021-02-05 03:07

    ​var obj = {
            id    : 'myid',
            token : 'sometoken'
        };
    
    alert($.param(obj));
    

    You can use $.param() to create your query-string parameters. This will alert id=myid&token=sometoken.

    This function is used internally to convert form element values into a serialized string representation.

    Here is a demo: http://jsfiddle.net/RdGDD/

    And docs: http://api.jquery.com/jquery.param

提交回复
热议问题