Easier way to transform FormData into query string

前端 未结 3 1204
渐次进展
渐次进展 2021-02-02 09:26

I’m sending a POST request via XMLHttpRequest with data entered into an HTML form. The form without interference of JavaScript would submit its data encoded as

3条回答
  •  清歌不尽
    2021-02-02 09:46

    If you could use JQuery, you'll simply call .serialize() function on your form object, like follow:

    function getQueryString() {
      var str = $( "form" ).serialize();
      console.log(str);
    }
    
    $( "#cmdTest" ).on( "click", getQueryString );
    
    
    



    Note: It also encode data for use it in url request

    I hope it helps you, bye.

提交回复
热议问题