How to deal with special characters in rest filters

Special characters in SharePoint Rest filters

You might have noticed while using SharePoint filters with special characters such as '&', '@' or '!' etc. you get error as we need to use encodeURIComponent in the rest api filtering. Below is the working example of filtering data from rest api having special character.

Code - 

function matchDataFromSPList(val){

        $.ajax({

                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('ListName')/items?$filter= ColumnName eq '"+encodeURIComponent(val)+"'",

                type: "GET",

                headers: {

                        "Accept": "application/json;odata=verbose"

                },

                async: false, 

                success: function(data) {                                                                       

                     if (data.d.results.length > 0) { 

                         

                       }          

                },               

                error: function (error) {  

                      alert(JSON.stringify(error)); 

                }         

      });

}




Comments

Popular posts from this blog

How to Customize exported excel's cell background color in Datatables

Customizing SharePoint list and implementing Quick search using jQuery

Populate dropdown using jquery ajax in SharePoint