提交包含特殊字符的值的表单

Submitting form with values containing special characters

本文关键字:表单 特殊字符 包含 提交      更新时间:2023-09-26
$('form').on('submit', function(submitEvent)
{
    $('table[id*=OtherOptions] :input').attr('disabled', false);
    $('#collapsiblePanel :input').attr('disabled', false);
    if (preventSubmit)
    {
        submitEvent.preventDefault();
        populateDateValues();
        populateContextFilterValues();
        if($.browser.msie)
        {
                $('#collapsiblePanelHiddenValues').val(JSON.stringify(collapsiblePanelObj));
        }
        var form = $(this);
        var formInput = decodeURIComponent(form.serialize());           
        $.getJSON('ValidateParams', formInput, function(data)
        { 
// Some more code here...

在上面的代码中,我正在使用表单数据对 struts2 操作进行验证调用,但如果某些表单字段包含 # 或 % 作为值,那么在服务器端获取请求参数时,这些特殊字符之后的所有参数都不会出现在请求参数映射中。

上述问题的解决方案是什么?

我能够通过不调用解码URIComponent而仅将序列化表单数据发送到服务器端来解决此问题,其中编码的数据由struts2自动解码。