Ajax call in SharePoint does not reach Web Service Method

In SharePoint, sometimes we might face a problem that everything in the code looks quite ok but the Ajax call is not reaching the web service. What I found that, the JavaScript code from where the Ajax call is done executes, but for some case the Ajax call is reaching the web service, for others it is not. While trying to debug using visual studio, the break point is not reached.

In SharePoint, any Ajax call must be done using the soap envelop. A sample soap envelop is as follows:

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>

    <soap:Body>

        <HelloWorld xmlns='http://tempuri.org/'> <dropdownParams>{"report":{"Dimension_Level":"[Country].[Country].[Country]","Dimension_Hierarchy":"[Country].[Country]","filter_id":"Country","params":[]}}</dropdownParams>

        </HelloWorld>

    </soap:Body>

</soap:Envelope>


 

Surely the soap envelop and soap body is a pure xml. In xml we cannot have some of the special characters like &, <, > and so on. So if we have these characters and we must pass them to the web service method, then we will have to replace these characters with their html encoding.

&

&amp;

<

&lt;

>

&gt;


 

So in JavaScript we will have to use the following code to do the adjustment.

soapEnv = soapEnv.replace(/&/g, '&amp;');

This resolves the problem and the Ajax call is successfully reaching the web service.