簡體   English   中英

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

[英]Submitting form with values containing special characters

$('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操作進行了驗證調用,但是如果某個表單字段包含#或%作為值,則在服務器端獲取請求參數時,這些特殊字符之后的所有參數都不會輸入請求參數映射。

以上問題的解決辦法是什么?

通過不調用encodeURIComponent並僅將序列化的表單數據發送到服務器端,struts2自動將編碼后的數據解碼,從而解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM