jquery - Javascript: submit form specyfing content type -
i use code submit form
var form = $("#some-form"); form.attr("action", url); form.attr("method", "post"); form.attr('target', '_blank'); form.submit();
the problem request sent has content-type: application/x-www-form-urlencoded
, (as mentioned here) encodes \n
characters in textareas of form %0d%0a
, decoded \r\n
on server side , cause many troubles.
i want server receive \n
, need content type.
so, questions are:
- what content type should use?
- how should change javascirpt use content type?
edit
i tried enctype="multipart/form-data"
, encodes new line characters same way.
use xmlhttprequest
(ajax)
it asynchronous , submits data page. plus can specify header. \n should arrive \n on server ajax.
var request = new xmlhttprequest; request.method = "post"; request.open(request.method, [url] , true); //true asynchronous //this part here matters. regular form data charset utf-8 request.setrequestheader("content-type", "application/x-www-form-urlencoded ; charset=utf-8"); request.setrequestheader("connection", "close"); request.onreadystatechange = [trackingfunction]; //you can see data returned post. request.send([arg]); //send post arguments here!
this seems work on machine. save data file , notepad doesn't register \n
newline. should've when lf
converted cr lf
Comments
Post a Comment