I have a form that I'm posting with the help of jQuery:
<form id="myForm" method="post" action="/processForm">
<input type="text" name="inputs" id="inputs"/>
<button id="submitButton">Submit Form</button>
</form>
$('#submitButton').click( function(event)
{
if(formValidatesOk(开发者_开发百科))
{
$("#myForm").submit();
}
}
But according to the headers reported by Firebug when the form is posted, no character encoding header is being submitted with the form - only this:
Content-Type: application/x-www-form-urlencoded
Could I use ajaxSetup to enforce utf-8 character encoding:
$.ajaxSetup({
scriptCharset: "utf-8" ,
contentType: "application/json; charset=utf-8"
});
I'm not sure if this is possible since I'm not using jQuery ajax here - I'm simply calling submit
on the form?
Using $.ajaxSetup
will only affect reqeusts sent via jQuery+AJAX. You can submit the form via AJAX when the user clicks submit, then redirect to another page when the request is returned to enforce utf-8.
You cannot, it just doesn't work this way. $.ajaxSetup()
really just extends the $.ajaxSettings
object which all $.ajax()
(and the shorthand versions) use when they execute...it has no effect on any other type of server request, it's exclusively for jQuery's ajax operations (or anything built on them)...but doesn't at all effect default <form>
behavior in the page.
精彩评论