Skip to main content
Known Participant
Mar 15, 2016 10:02 AM UTC
Answered

jquery ajax get works but 500 error is thrown

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>

This topic is closed to new replies. Start a new post to keep the conversation going.
WolfShade
WolfShadeCorrect answer
Legend
Mar 15, 2016 1:34 PM UTC

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,

^_^

8 replies

WolfShade
WolfShadeCorrect answer
Legend
Mar 15, 2016 1:34 PM UTC

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,

^_^

Translate
AkosFAuthor
Known Participant
Mar 16, 2016 11:05 AM UTC

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

Translate
WolfShade
Legend
Mar 16, 2016 1:13 PM UTC

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,

^_^

Translate