-1

Have a example object:

data = {
    var1: 'val 1',
    var2: 'val 2'
}

Hot to transform to application/x-www-form-urlencoded content?, with jquery transform only from form objects but not from javascript objects.

The expect: var1=val+1&var2=val+2

e-info128
  • 3,727
  • 10
  • 40
  • 57

1 Answers1

0

You can do something like this to iterate over the object:

Object.keys(data).map(x=>x+'='+data[x]).join('&').replace(/ /g,'+')

Result:

var1=val+1&var2=val+2