# Migrating from cfjaxaproxy using $.ajax() issues

**URL:** <https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932>\
**Category:** dev\
**Created:** [April 3, 2025, 4:05am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932 "2025-04-03T04:05:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiniFireDragon](https://dev.lucee.org/user_avatar/dev.lucee.org/minifiredragon/32/8126_2.png) [@MiniFireDragon](https://dev.lucee.org/u/MiniFireDragon)\
**Post date:** [April 3, 2025, 4:05am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/1 "2025-04-03T04:05:33Z")

</div>

I am moving old code from cfajaxproxy to using $.ajax(). And in doing so, I am having problems sending objects to a cfc. I am not sure if this is Lucee, or my lack of knowledge on how to use ajax. Here is a shortened code bit:

var o = {};  
o.sellerID = \_sellerID;  
var js = JSON.stringify(o);

> $j.ajax(  
> {  
> type: “POST”,  
> url: “…/admin/cfc/tools.cfc?method=getTableSchema”,  
> data:  
> {  
> thisData: js,  
> returnFormat: “json”,  
> },  
> dataType: “json”,  
> success: getTableSchema,  
> });

When Lucee recieves it, it complains that it cannot convert a String to a Struct. I tried to send just the object (which works find in cfajaxproxy) without stringy, but it posts something that is clearly not a struct.

Is there something I am missing?

**OS** : Rocky Linux 9  
**Java Version** : OpenJDK 21.0.6  
**Tomcat Version** : Tomcat 9.0.102  
**Lucee Version** : Lucee 6.2.0.321

---

<div class="post-metadata">

**Author:** ![Zackster](https://dev.lucee.org/user_avatar/dev.lucee.org/zackster/32/3484_2.png) [@Zackster](https://dev.lucee.org/u/Zackster)\
**Post date:** [April 3, 2025, 7:36am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/2 "2025-04-03T07:36:23Z")

</div>

> [@MiniFireDragon](#):
>
> but it posts something that is clearly not a struct.

kinda missing a vital clue here! what does it look like?

my tarot reader is on holiday 🙂

also what does your cfc look like?

---

<div class="post-metadata">

**Author:** ![MiniFireDragon](https://dev.lucee.org/user_avatar/dev.lucee.org/minifiredragon/32/8126_2.png) [@MiniFireDragon](https://dev.lucee.org/u/MiniFireDragon)\
**Post date:** [April 3, 2025, 7:45am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/3 "2025-04-03T07:45:32Z")

</div>

Here is a snippet of the modified version so I can make it work between a cfinvoke and a ajax call. the cfargument was set to struct.

```auto
 <cffunction name="getTableSchema" access="remote" output="false" returntype="struct">
 	<cfargument name="thisData" required="true" type="any" />
 
 	<cfif isStruct(arguments.thisData) >
 		<!--- don't change it --->
 	<cfelse>
 		<cfset arguments.thisData = deserializeJSON(arguments.thisData) />	
 	</cfif>
 	<cfreturn >
 </cffunction>

```

The data sent before stringify was applied:

> thisData[sellerID]:“MiniFireDragon”`

---

<div class="post-metadata">

**Author:** ![MiniFireDragon](https://dev.lucee.org/user_avatar/dev.lucee.org/minifiredragon/32/8126_2.png) [@MiniFireDragon](https://dev.lucee.org/u/MiniFireDragon)\
**Post date:** [April 3, 2025, 7:54am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/4 "2025-04-03T07:54:08Z")

</div>

When I set the cfargument to struct, this is what I get back from the server:

```auto
Lucee 6.2.0.321 Error (expression)
Message Invalid call of the function [getTableSchema], first Argument [thisData] is of invalid type, Cannot cast String [{"sellerID":"MiniFireDragon"}] to a value of type [struct]

```

the json passed (as it indicate in the error):

> thisData:‘{“sellerID”:“MiniFireDragon”}’

---

<div class="post-metadata">

**Author:** ![Zackster](https://dev.lucee.org/user_avatar/dev.lucee.org/zackster/32/3484_2.png) [@Zackster](https://dev.lucee.org/u/Zackster)\
**Post date:** [April 3, 2025, 8:17am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/5 "2025-04-03T08:17:47Z")

</div>

this is my test.cfc

```auto
component remote="true"{
	remote function test( asString, asObject ) returnFormat="json" {
		systemOutput(arguments, true);
		return arguments.toJson();
	}
}

```

and my index.cfm

```auto

<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](https://dev.lucee.org/uploads/short-url/y25iL3xwNr8shvEmWoXIPD8iCpb.zip) (1.2 KB)

what i’m seeing is

```auto
/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

```auto
/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

```auto
{"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

![image](https://dev.lucee.org/uploads/default/original/2X/2/2a854f5e95ae31058fc5ed2d3a50a1ea5c2a108a.png)

---

<div class="post-metadata">

**Author:** ![MiniFireDragon](https://dev.lucee.org/user_avatar/dev.lucee.org/minifiredragon/32/8126_2.png) [@MiniFireDragon](https://dev.lucee.org/u/MiniFireDragon)\
**Post date:** [April 3, 2025, 6:29pm UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/6 "2025-04-03T18:29:36Z")

</div>

I am still using the old style of cfc functions (as you can see), so I am not sure if what you have is the same as what I have. If I understand what are you doing, your arguments are not defined to a specific type.

As I mentioned I do not have a problem sending with it is an “any”, it is when it goes up as a json string, Lucee, for some reason cannot convert the string to a struct, and it is clearly a json formated chain, and deserializeJSON works on the string as well.

---

<div class="post-metadata">

**Author:** ![kenricashe](https://dev.lucee.org/user_avatar/dev.lucee.org/kenricashe/32/3476_2.png) [@kenricashe](https://dev.lucee.org/u/kenricashe)\
**Post date:** [April 20, 2025, 6:22am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/7 "2025-04-20T06:22:24Z")

</div>

`$.ajax()` is old code also. Most devs switched back to plain vanilla js (or like me are in the slow process of paying off technical debt) ever since HTML5 made jQuery obsolete.

**plain vanilla HTML5 JavaScript**

```auto
<script>
// your code here
fetch('foo.cfm', {
	method: 'POST',
	headers: {'Content-Type': 'application/json'},
	body: JSON.stringify(o)
})
.then(result => {
	return result.json();
})
.then(data => {
	console.log(data);
});
</script>

```

**foo.cfm**

```auto
<cfscript>
data = deserializeJSON(toString(getHTTPRequestData().content));
</cfscript>

```

---

<div class="post-metadata">

**Author:** ![MiniFireDragon](https://dev.lucee.org/user_avatar/dev.lucee.org/minifiredragon/32/8126_2.png) [@MiniFireDragon](https://dev.lucee.org/u/MiniFireDragon)\
**Post date:** [January 16, 2026, 5:58am UTC](https://dev.lucee.org/t/migrating-from-cfjaxaproxy-using-ajax-issues/14932/8 "2026-01-16T05:58:52Z")

</div>

Not trying to revive this thread. This is an FYI to this Post for those who have come across it, as I spent a few hours scratching my head (and please correct me if I am wrong) trying to figure out how to POST data to a CFC Function with arguments.

@kenricashe code above will not work when passing data to a CFC function with arguments required. ie;

```auto
remote void function loadOffset( required numeric thisOff)
    {
        Session.MM_TimeZone = arguments.thisOff;   
    }

```

The CFC function will not find its answers in the Body tag. The only way to pass information is to load it into the URL (javascript):

```auto
let d = new Date();
let timeOff = d.getTimezoneOffset();

fetch('/cfc/user.cfc?method=loadOffset&thisOff='+timeOff, 
{
        method: 'POST',
});

```

The problem with this is there can only be so much information passed into the URL before the server kicks an error (or is this different with fetch?)

To bypass the issue, you will need to leave the comfort of having the CFC Function argument types verify the data and do it yourself inside the cfc.

I have not tested this, but this came from stackoverflow :

```auto
(*
Source - https://stackoverflow.com/a
Posted by Vineesh
Retrieved 2026-01-16, License - CC BY-SA 3.0
*)

remote array function createObj() returnFormat = "JSON" {
     WriteDump(deserializeJSON(ToString(getHTTPRequestData().content)));
     myObj = deserializeJSON(ToString(getHTTPRequestData().content));
     cfhttp(url="http://myServer/ObjAPI/Obj", method="POST", result="getResponse") {
         cfhttpparam(type="header", name="Content-Type", value="application/json");
         cfhttpparam(type="body", value=SerializeJSON(myObj));
     } 
}

```

The important part of the code is the myObj line.
