Search code examples
javascriptjqueryajaxcoldfusioncoldfusion-9

ColdFusion Calling CFC page for ajax


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!


Solution

  • 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.