简体   繁体   中英

ajaxSubmit causes incorrect character decoding

Consider the following simple Asp page - a form with one text input and a submit button:

<%
    response.write(Request.Form("test") & "<br/>")
%>

<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>

<form action="test.asp" method="post" id="form" name="form" accept-charset="ISO-8859-1">
    <input type="text" name="test" />
    <input type="submit" id="sub" />
</form>

<script type="text/javascript" />
    $('#form').submit(function () {
        $('#form').ajaxSubmit({
            success : function(responseText){

            },
            error : function(){
            }
        });

        return false;
    }); 
</script>

Using the value ® :

If I submit the form without ajax (not using the bottom script block), the response is ® . The data gets encoded as test=%AE .

If I submit the form with ajax (using the bottom script block), the response is ® . The data gets encoded as test=%C2%AE .

Since %C2%AE is the valid encoding for ® , is this a vbscript issue?

If I submit the form without ajax (not using the bottom script block), the response is ®. The data gets encoded as test=%AE.

This is because of the accept-charset="ISO-8859-1" . ajaxSubmit , on the other hand, always uses UTF-8, ignoring any accept-charset . (This is probably because limitations on AJAX mean that any other encoding will break in some scenarios).

I suggest removing the accept-charset attribute (which doesn't work like it should in IE anyway) and serving the page explicitly as UTF-8. This should get rid of the ® problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM