Highlighted

jquery ajax get works but 500 error is thrown

New Here ,
Mar 15, 2016

Copy link to clipboard

Copied

Hi guys, I have this issue where I'm using Jquery to get a simple string from a cfc and although the string is returned correctly I also get a bunch of unwanted HTML code appended to the response. The HTML  code is CF's 500 error page.
It does not happen if I comment out the ajax call but as soon as I put it back it happens.  It's driving me nuts.  There are no errors listed in the logs.  The original application was not written by me and it uses application.cfm and onrequestend.cfm, I've commented out all code in onrequestend.cfm in case that's what's causing it but no change.   I've attached screenshots of the alert pop up where you can see that the response is there at the top.
Been browsing for a solution but cannot find it. Not sure where to start debugging it.  It must be something soo simple that I overlook. Any help would be much appreciated.
Here's my simple JS:

var thisEmail = $('#emailAddress').val();

$.ajax({

  type: "get",

  url:"cfcs/subscribe.cfc?returnformat=plain&email="+thisEmail,

  data: { method: "doSubscribe" },

  cache:false,

  normalizeJSON: true,

  success: function(data) {

  alert(data);

  });

Here's my simple CFC function:

<cffunction name="doSubscribe" access="remote" returntype="any" returnFormat="plain" output="no">

   

  <cfargument name="email" type="string" required="yes">

      

  <cfreturn "test response">

        

   

  </cffunction>

Capture.PNGCapture2.PNG

My suggestion would be to change the "get" to a "post", get rid of the argument from the CFC and use the form scope.

Also, I suggest removing the success callback from within the .ajax() and append .done() to the end of the .ajax() function, with the success code inside the .done() portion.

I must admit, though, that I'm stumped as to why HTML is being returned with the string.  Clearly the cfc has been found, or you wouldn't be getting the "test response" string.

HTH,

^_^

TOPICS
Connector

Views

2.4K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

jquery ajax get works but 500 error is thrown

New Here ,
Mar 15, 2016

Copy link to clipboard

Copied

Hi guys, I have this issue where I'm using Jquery to get a simple string from a cfc and although the string is returned correctly I also get a bunch of unwanted HTML code appended to the response. The HTML  code is CF's 500 error page.
It does not happen if I comment out the ajax call but as soon as I put it back it happens.  It's driving me nuts.  There are no errors listed in the logs.  The original application was not written by me and it uses application.cfm and onrequestend.cfm, I've commented out all code in onrequestend.cfm in case that's what's causing it but no change.   I've attached screenshots of the alert pop up where you can see that the response is there at the top.
Been browsing for a solution but cannot find it. Not sure where to start debugging it.  It must be something soo simple that I overlook. Any help would be much appreciated.
Here's my simple JS:

var thisEmail = $('#emailAddress').val();

$.ajax({

  type: "get",

  url:"cfcs/subscribe.cfc?returnformat=plain&email="+thisEmail,

  data: { method: "doSubscribe" },

  cache:false,

  normalizeJSON: true,

  success: function(data) {

  alert(data);

  });

Here's my simple CFC function:

<cffunction name="doSubscribe" access="remote" returntype="any" returnFormat="plain" output="no">

   

  <cfargument name="email" type="string" required="yes">

      

  <cfreturn "test response">

        

   

  </cffunction>

Capture.PNGCapture2.PNG

My suggestion would be to change the "get" to a "post", get rid of the argument from the CFC and use the form scope.

Also, I suggest removing the success callback from within the .ajax() and append .done() to the end of the .ajax() function, with the success code inside the .done() portion.

I must admit, though, that I'm stumped as to why HTML is being returned with the string.  Clearly the cfc has been found, or you wouldn't be getting the "test response" string.

HTH,

^_^

TOPICS
Connector

Views

2.4K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 15, 2016 0
LEGEND ,
Mar 15, 2016

Copy link to clipboard

Copied

My suggestion would be to change the "get" to a "post", get rid of the argument from the CFC and use the form scope.

Also, I suggest removing the success callback from within the .ajax() and append .done() to the end of the .ajax() function, with the success code inside the .done() portion.

I must admit, though, that I'm stumped as to why HTML is being returned with the string.  Clearly the cfc has been found, or you wouldn't be getting the "test response" string.

HTH,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 15, 2016 0
New Here ,
Mar 16, 2016

Copy link to clipboard

Copied

thank you, I completely reworked it all as you suggested and it seems to work.  It puzzles me as my original method has been used on many many different apps without issues.
This just remains a mistery for now.
Thanks you again for the suggestion.

Cheers

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 0
LEGEND ,
Mar 16, 2016

Copy link to clipboard

Copied

Glad I could be of assistance.  And thank you for marking my answer as correct, I really appreciate it.

Just out of curiosity - has anything changed in your environment that could have caused this?  CF updated?  Server OS updated?  Java updated?  Network security settings?  Anything?

V/r,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 0
New Here ,
Mar 16, 2016

Copy link to clipboard

Copied

nothing that I am aware of...I forgot to say that it's now all driven by a .cfm file rather than .cfc as it still wouldn't have it with using .cfc so the problem must lie around that somewhere.
thank you again.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 0
LEGEND ,
Mar 16, 2016

Copy link to clipboard

Copied

Just curious.  In your ajax call, have you tried setting the URL so that it goes from the root of your domain?

url: "/path/to/cfcs/myFunction.cfc?method=thisFunction",

HTH,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 0
New Here ,
Mar 16, 2016

Copy link to clipboard

Copied

I tried it two ways:

1. in the root like url: "subscribe.cfc"
2. in a  subfolder url: "cfcs/subscribe.cfc"

both worked the same way, both returned the correct response correctly so that means the cfc was found yeah ? yet appended that 500 html to it all.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 0
LEGEND ,
Mar 16, 2016

Copy link to clipboard

Copied

That is so weird.  I can't think of how that 500 error could be popping up.  Could there be something in application.cfm that's causing it?

V/r,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 0
Most Valuable Participant ,
Mar 16, 2016

Copy link to clipboard

Copied

I wonder if there's an issue with onRequestEnd.cfm treating CFC requests the same as CFM requests.  Maybe add some logic to look at the file extension of the requested page and bypass any processing if the extension is "cfc"?  That's commonly done in the onRequestStart() method of Application.cfc (check if the request is from a CFC, if so delete the onRequest() method so it doesn't process).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 16, 2016 1