This is a further discussion on:
https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932
As I do not think I made the issue clear enough. When I look at @Zackster 's code:
component remote="true"{
remote function test( asString, asObject ) returnFormat="json" {
systemOutput(arguments, true);
return arguments.toJson();
}
}
There is no definition of what the variables are ie;
component remote="true"{
remote function test( required string asString, required struct asObject ) returnFormat="json" {
systemOutput(arguments, true);
return arguments.toJson();
}
}
When you add in the required struct Lucee throws an error:
"request","The parameter [asObject] to function [test] is required but was not passed in.lucee.runtime.exp.ExpressionException: The parameter [asObject] to function [test] is required but was not passed in.
asObject,test
When I remove the required, it goes through, but what ever Lucee did to the struct, I cannot seem to extract the data correctly. This is a message I am seeing:
The key [asObject] doesn't exist in the arguments scope. The existing keys are [asString, asObject[sellerID], asObject[name]]
And I have tried multiple ways, and get different errror answers:
st.name = arguments[asObject];
st.name = arguments[asObject[name]];<--- this one gives me an error that it cannot find name
st.name =arguments[asObject][name];
st.name =arguments[asObject].name;
not really sure what other combinations I need to use to get to it
And this is the updated cfc:
component remote="true"{
remote function test( required string asString, struct asObject ) returnFormat="json" {
var st = {};
st.name = arguments.asObject.name;
systemOutput(arguments, true);
return arguments.toJson();
}
}
And just for clarity sake, here is the index.cfm I am using (copied from previous post):
<cfscript>
if (cgi.REQUEST_METHOD eq "post"){
echo(form.toJson());
abort;
}
</cfscript>
<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
<script>
var o = {};
o.sellerID = "lucee";
o.name ="zac";
var js = JSON.stringify(o);
var endpoints = ["/ajax/index.cfm", "/ajax/test.cfc?method=test"];
for (i=0; i < endpoints.length; i++ ){
test(endpoints[i]);
}
function test(e){
document.write("<h1>" +e+ "</h1>");
$.ajax({
type: "POST",
url: e,
data:
{
asString: JSON.stringify(o),
asObject: o
},
dataType: "json",
success: function(data){
console.log(e);
console.log(data);
document.write("<h1>"+ e + "</h1>" + JSON.stringify(data));
},
error: function(data){
console.error(data);
}
});
}
</script>
And the current stack I am running (keep in mind this reaches back to Lucee 6 as well):
Version Lucee 7.0.1.100
Loader Version 7.0.0.395
Servlet Container Apache Tomcat/11.0.13
Java 21.0.9 (Eclipse Adoptium) 64bit
OS Linux (5.14.0-611.13.1.el9_7.x86_64) 64bit
Architecture 64bit