开发者

Filtering ajax input

开发者 https://www.devze.com 2023-02-07 11:42 出处:网络
I\'m building a front-end content editing module for my own framework using a WYSIWYG editor. All is going well except that the WYSIWYG editor uses html which includes & and =. When I try to submi

I'm building a front-end content editing module for my own framework using a WYSIWYG editor. All is going well except that the WYSIWYG editor uses html which includes & and =. When I try to submit this ajax will see i开发者_如何转开发t as another get or post var instead of 1 big var.

Now I could just fix this using .Replace to something and replacing it back server side, but I was hoping for a more standarized solution. Does anyone know of any?

Bottomline: I'm asking if there is a standarized method to filter input for ajax.

Code:

function submitData(content) 
{
    //Send it to save the edited content
    $.ajax({ url: 'index.php?ajaxCall=1&module=content&action=updateContent',
            type: "POST",
            data: "id=59&content=" + content.current,
            success: 
                function(result)
                {
                    alert(result);
                }
            });
}

Rob


If you are constructing your URI or POST body manually, you want encodeURIComponent.

If you are using a helper library for Ajax, then you should probably be using that instead.

e.g. for jQuery:

{
    data: {
        myFieldName: stringOfHTML
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消