Problems adding to list and submitting via html form and jquery -



Problems adding to list and submitting via html form and jquery -

i working on node.js app. on client side have next

input(type='hidden', name='imgurl', id="categorylist", value='[]') ... var images = $.parsejson($('#categorylist').val()) images.push(data.result.secure_url) var jsonimages = json.stringify(images) $('#categorylist').val(jsonimages)

then save orchestrate db this...

exports.addtodb = function(req, res, next){ console.log(req.body) if(req.params.type) db.put(req.params.type, uuid.v4(), req.body, false) next(); }

problem when saved, looks like...

"imgurl": "[\"https://res.cloudinary.com/dbkbp16kc/image/upload/v1403448829/img.png\"]"

a 'normal' 1 looks like...

"imgurl": [ "https://f0.bcbits.com/img/a2976218772_2.jpg" ]

as can see seems escaping of quotes causing issue. know how alter way handled?

this happens because stringify json.

remove var jsonimages = json.stringify(images) , instead set images direclty value of '#categorylist'

input(type='hidden', name='imgurl', id="categorylist", value='[]') ... var images = $.parsejson($('#categorylist').val()) images.push(data.result.secure_url) $('#categorylist').val(images)

update

@jackie "imgurl": "[\"https://res.cloudinary.com/dbkbp16kc/image/upload/v1403448829/img.png\"]" because stringifying json. if need jsonimages used somewhere else improve json.parse(images) while setting val of #categorylist

var jsonimages = json.stringify(images) ... $('#categorylist').val(json.parse(jsonimages))

jquery html css node.js

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -