다음을 통해 공유


SP.Utilities.HttpUtility Class

Applies to: SharePoint Foundation 2010

Provides access to methods used to encode and decode strings during the processing of web requests.

SP.Utilities.HttpUtility

Example

The following example creates an input button on an application page that encodes the URL of the All Tasks View of the current site, and then navigates to the msn.com site.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    var web;
    var view;
    var newUrl;
    function runCode() {
        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            web = clientContext.get_web();
            var listCollection = this.web.get_lists();
            var list = listCollection.getByTitle("Tasks");
            this.view = list.get_views().getByTitle("All Tasks");
            clientContext.load(this.view);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {

        var viewServ = this.view.get_serverRelativeUrl();
        var encodedUrl = SP.Utilities.HttpUtility.ecmaScriptStringLiteralEncode(viewServ);
        newUrl = 'https://www.msn.com';
        
        alert('Encoded All Tasks View URL: ' + encodedUrl);
        alert('Navigating to msn.com...');
        SP.Utilities.HttpUtility.appendSourceAndNavigateTo(this.newUrl);
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

See Also

Reference

SP.Utilities.HttpUtility Methods

SP.Utilities Namespace