Hi,
This is not a Lucee question but rather jquery’s ajax call to return a simple value.
code looks like this:
$.get("myCFC.cfc?method=CheckStatus",{id:i, Name:name},function(data){console.log(data);});
// this CFC would return either 1 or 0
debugging output looks this:
` Dev App
some rendered html code here...
<wddxPacket version=‘1.0’><header/><data><number>1.0</number></data
></wddxPacket>`
what I need to return is the 1 or 0 simple value from the myCFC call. what do I need to do?
Thanks.
try a returnType=“json” on the checkStatus function?
No, that bombed out, when I didn’t specify returnType it seemed to use “numeric” for when I used returnType=“numeric” it returned the same as I posted.
In the meantime, I’ve opted to another solution. Thanks tho.
You actually need returnFormat="JSON"
in the component.
For future viewers of this thread, this actually works:
index.cfm:
<!DOCTYPE html>
<html>
<head>
<title>Get test</title>
</head>
<body>
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script>
$(function(){
$.get(
"myCFC.cfc?method=CheckStatus",
{id:"2", Name:"Hello"},
function(data){
console.log(data);
}
);
})
</script>
</body>
</html>
And the myCFC.cfc :
component {
remote numeric function CheckStatus(numeric id, string Name)
returnFormat="JSON"
{
return 1;
}
}
This returns you 1
with the right application/JSON
header.
Looks like remote components return WDDX by default, which might seem a bit outdated now IMHO.