There is a form with input
<form> <input type="text" name="name" value="Имя публикации" /> </form>
Using jQuery I get data
inputs = $("form").serialize().split('&');
At the exit I get
["name=%D0%98%D0%BC%D1%8F+%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D0%BA%D0%B0%D1%86%D0%B8%D0%B8"]
How to bring the line to normal? If you use decodeURI, then spaces are replaced by pluses.
I need to send the form Ajax with data and files
function getData(form) { /* get data from form */ var data = new FormData() inputs = form.serialize().split('&'); inputs.forEach(function(item, i, arr) { var tmp = item.split('='); data.append(tmp[0],decodeURIComponent(tmp[1].replace(/\+/g, ' '))); }); /* get files */ form.find("input[type='file']").each(function(){ var key = $(this).attr('name'); var file = $(this).prop('files')[0]; if (file !== 'undefined') { data.append(key, file); } }); return data; }
decodeURIComponent(t).replace(/\+/g, ' ')
? - user207618$.post($(form).attr('action'), $(form).serialize(), successCallback)
. - Sergey Gornostaev