JavaScript How to call cffunction on the cfm page from javascript?

I was wondering if I can call cffunction on my cfm page? I have onClick button that should make a call to the cffunction that is on the same page. Also I have tried to put cfcomponent around my function but I was getting this error:

Invalid CFML construct found on line 94 at column 1.
ColdFusion was looking at the following text:

<
The CFML compiler was processing:
< marks the beginning of a ColdFusion tag.Did you mean LT or LTE?

So far I have this:

<cffunction name="getRecords" access="remote">
    <script>
        alert('test');
    </script>
</cffunction>

here is my JS Function:

function getRecs(){
    try{
        location.href = 'myCFMpage.cfm?method=getRecords';
    }catch(err){
        alert('Error')
    }   
}

I'm not sure if this even possible, my current code did not trigger alert in cffunction. Reason why I'm trying to do this because I have a cfquery on this page and I want to grab the data from that query when user click on the button and then to do some manipulation. If anyone can tell me if this is possible or is there any better way to approach this problem please let me know.

Answer:1

I am looking for a way to turn a middleware on and off. I introduced a tutorial functionality - I listen to what the user is doing with the UI by checking each action with a "guidance" middleware. if ...

I am looking for a way to turn a middleware on and off. I introduced a tutorial functionality - I listen to what the user is doing with the UI by checking each action with a "guidance" middleware. if ...

I have a bunch of polygons which are stored in a database. I would like to add them to the map in such a way that they can be edited using the leaflet-draw toolbar. Although, now the polygons get ...

I have a bunch of polygons which are stored in a database. I would like to add them to the map in such a way that they can be edited using the leaflet-draw toolbar. Although, now the polygons get ...

Can the localStorage be cleared for a specific application? The usecase is the following: - we have a self built application called "Agent Cockpit" which is sharing the same domain name like ...

Can the localStorage be cleared for a specific application? The usecase is the following: - we have a self built application called "Agent Cockpit" which is sharing the same domain name like ...

  1. localstorage clear specific key
  2. localstorage clear specific item
  3. localstorage clear specific

I have a page where an anchor tag has id. When the anchor tag is clicked I am fetching the value to input type hidden and after again clicking on the same div it should be removed. The selection will ...

I have a page where an anchor tag has id. When the anchor tag is clicked I am fetching the value to input type hidden and after again clicking on the same div it should be removed. The selection will ...

  1. value onclick javascript
  2. value onclick
  3. value onclick submit