Skip to main content
Known Participant
March 15, 2016
Answered

jquery ajax get works but 500 error is thrown

  • March 15, 2016
  • 1 reply
  • 3914 views

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 has been closed for replies.
Correct answer WolfShade

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,

^_^

1 reply

WolfShade
WolfShadeCorrect answer
Legend
March 15, 2016

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,

^_^

AkosFAuthor
Known Participant
March 16, 2016

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

WolfShade
Legend
March 16, 2016

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.


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,

^_^