You need to sign in to do that
Don't have an account?
Accessing Apex WebService from jQuery
I need to know if it's possible to retrieve some data from SFDC via jQuery. I created a sample apex webservice to do this. Then the webservice will be accessed from a 3rd party website via jQuery. Problem is when it executes the processResponse() function, an exception is thrown because the xmlHttpRequest.responseXML is NULL. What seems to be the problem? =(
Here's the code of the webservice:
global class TARetrieveArticlesWebService {
WebService static String GetArticles()
{
In_Depth__c sampleData = [SELECT Name FROM In_Depth__c LIMIT 1];
return sampleData.Name;
}
}
And here's the code that I placed in the 3rd party site:
<head>
<script src='https://xxxxxxxx.full.cs1.force.com/SiteName/resource/jQuery_1_4_2' type='text/javascript'/>
</head>
<script type='text/javascript'>
var soapMessage = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><soap:Body><methodCall>GetArticles</methodCall></soap:Body></soap:Envelope>";
$.ajax({
url: "http://xxxxxxxx.full.cs1.force.com/SiteName/services/Soap/class/TARetrieveArticlesWebService/GetArticles/",
type: "POST",
dataType: "xml",
data: soapMessage,
complete: processResponse,
contentType: "text/xml; charset=\"utf-8\""
});
function processResponse(xmlHttpRequest, status)
{
$(xmlHttpRequest.responseXML).find('methodResponse').each(function()
{
var name = $(this).find('response').text();
alert(name);
});
}
</script>
Don't you need to pass the sessionId or authentication parameter?
Regards
-H