0

Hey all I am trying to call the following cfm page in order to call a cfc page via ajax:

https://dev-thesite.com/personnel/search.cfm page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <script> $(document).ready(function() { $.ajax({ type:'GET', url: 'search_ajax.cfc?method=searchAward', data: { Totals:'100', CodeNum:'165161', TestYear:'2016', SelType:'blah', SelJuris:'juris' }, success: function(data) { alert(data); }, error: function(data) { console.log('err: ', data); } }); }); </script> <div id="testing"></div> 

https://dev-thesite.com/personnel/search_ajax.cfc page:

<cfcomponent> <cffunction name="searchAward" access="remote" returntype="string"> <cfargument name="Totals" type="string" required="true"> <cfargument name="CodeNum" type="string" required="true"> <cfargument name="TestYear" type="string" required="true"> <cfargument name="SelType" type="string" required="true"> <cfargument name="SelJuris" type="string" required="true"> <cfscript> if(arguments.Totals = '5'){ return 'YES!'; } else { return 'NO!'; } </cfscript> </cffunction> </cfcomponent> 

Currently when running this I get the error side of the ajax call.

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.

Any help would be great at fixing this error in ColdFusion 9!

6
  • Go into CFAdmin and enable debugging so that you can see the error. It looks like you're using an assignment statement instead of a comparison in your if clause. Commented Sep 6, 2016 at 13:32
  • Also, it looks like arguments needs to be Arguments according to the docs Commented Sep 6, 2016 at 13:37
  • Call the method directly from ColdFusion and see if the error occurs. Commented Sep 6, 2016 at 13:39
  • @DanBracuk yes, it does have the same 500 error when going to dev-thesite.com/personnel/… Commented Sep 6, 2016 at 13:47
  • You need to tick "Enable Robust Exception Information" under the Debugging Settings in CF Administrator to see what's going on. With a plain "500 Oops something went wrong" error, all bets are off. Commented Sep 6, 2016 at 13:58

1 Answer 1

2

Well it looks like all that was wrong was changing this:

if(arguments.Totals = '5'){ 

to this:

if(arguments.Totals eq '5'){ 

Just adding the eq seems to have fixed it oddly enough.

Sign up to request clarification or add additional context in comments.

2 Comments

eq is ColdFusion's traditional equality operator. From ColdFusion 9 onwards you can write it as == in <cfscript> sections. = is the assignment operator. I haven't spotted it, either. (compare the documentation)
Makes total sense. In the original you just had a var set to "5" - that's probably resulting in your 500 error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.