This little bit of code allows you to call a web service from JavaScript. I have found many articles and ways of doing this on the interweb and non of them seem to work. This one works with CF web services.
The interesting thing i found is you don't need to pass parameters using the XMLHttpRequest method, to call a specific function just append &method= to the end of the wsdl string.
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("myDivResponse").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("GET","http://myurl/webserrvices/mycfc.cfc?WSDL&method=getSomething",true);
xmlHttp.send(null);
}
No comments:
Post a Comment