this is my test.cfc
component remote="true"{
remote function test( asString, asObject ) returnFormat="json" {
systemOutput(arguments, true);
return arguments.toJson();
}
}
and my index.cfm
<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>
ajax.zip (1.2 KB)
what i’m seeing is
/ajax/index.cfm
{"asString":"{\"sellerID\":\"lucee\",\"name\":\"zac\"}","asObject[sellerID]":"lucee","asObject[name]":"zac","fieldnames":"asString,asObject[sellerID],asObject[name]"}
/ajax/test.cfc?method=test
"{\"asString\":\"{\\\"sellerID\\\":\\\"lucee\\\",\\\"name\\\":\\\"zac\\\"}\",\"asObject\":null,\"asObject[sellerID]\":\"lucee\",\"asObject[name]\":\"zac\"}"
and in the console
/ajax/index.cfm
ajax/:24 {asString: '{"sellerID":"lucee","name":"zac"}', asObject[sellerID]: 'lucee', asObject[name]: 'zac', fieldnames: 'asString,asObject[sellerID],asObject[name]'}asObject[name]: "zac"asObject[sellerID]: "lucee"asString: "{\"sellerID\":\"lucee\",\"name\":\"zac\"}"fieldnames: "asString,asObject[sellerID],asObject[name]"[[Prototype]]: Object
ajax/:23 /ajax/test.cfc?method=test
ajax/:24 {"asString":"{\"sellerID\":\"lucee\",\"name\":\"zac\"}","asObject":null,"asObject[sellerID]":"lucee","asObject[name]":"zac"}
and the tomcat console
{"asString":"{""sellerID"":""lucee"",""name"":""zac""}","asObject":nullValue(),"asObject[sellerID]":"lucee","asObject[name]":"zac"}
the asObject":nullValue()
is a bit strange TBH, Lucee 5 does the same
