0

I have a form with following structure:

<form id="example" class="form" method="post" action="/edu/example/education_document/update">
    <div class="education_document">
        <div class="form-group">
            <label for="education_document_file">Fil</label>
            <input class="form-control" id="education_document_file" type="file" value="" name="education_document_file">
        </div>
        <div class="form-group">
                <label for="education_document_name">Namn&nbsp;*</label>
                <input class="form-control" id="education_document_name" type="text" value="tese+test" name="education_document_name" required="">
        </div>
        <div class="form-group">
                    <label for="education_document_description">Description</label>
                    <textarea class="form-control" name="education_document_description" placeholder="Description" rows="5"></textarea>
        </div>
        <div class="btn-container">
            <div class="btn-container-inner">
                <div class="btn-row">
                    <div class="pull-right">
                    <button type="submit" name="save" id="save" value="save" class="btn btn-primary Spara" data-loading-text="Spara">Save/button>
                    <button type="submit" name="cancel" id="cancel" value="cancel" class="btn btn-default Avbryt" data-loading-text="Avbryt">Cancel</button>
                    </div>
                </div>
            </div>
        </div>
</form>. 

I serialize using form.serialize();. In my ajax call I have made the contentType and processData parameter false based on the following [Stack overflow : For uncaught-type error-illegal invocation].

But nowI have problems in encoding. For example if I give 'space' in input filed I get plus and '&' I get %26. Based on following link I tried serialize [Serialize-convert-space to plus problem][1] [1]: jQuery serialize converts all spaces to plus. But the problem with '&' is still continuing and space to '+' is solved

Community
  • 1
  • 1
jenny
  • 277
  • 7
  • 18
  • Please include your JS code in the question as that's where the issue is – Rory McCrossan Nov 14 '16 at 12:49
  • Here is my javascript . https://jsfiddle.net/j2Lw8bps/ – jenny Nov 14 '16 at 12:58
  • `&` is `%26` url-encoded. – Mornor Nov 14 '16 at 13:27
  • But on adding the following code after "&" in description field disappers. $.fn.serializeAndEncode = function() { return $.map(this.serializeArray(), function(val) { return [val.name, encodeURIComponent(val.value)].join('='); }).join('&'); }; – jenny Nov 14 '16 at 13:37

0 Answers0