Skip to main content
ajithman
Inspiring
August 6, 2009
Question

Ajax call in ModelGlue without rendering a view

  • August 6, 2009
  • 1 reply
  • 668 views

Hi All,

     I am using Ajax with ModelGlue. I want to make an Ajax call to return a value. I do not want to render any view. I just want a database interaction and bring back a value.

My Ajax call:

new Ajax.Request(root+'test.testFunction',{

method: 'post',

parameters: {param1:paramval},

onSuccess: function(response){

alert(response.responseText);

var myresult = response.responseText;

}

})

my modelglue event :

<event-handler name="test.testFunction">

     <broadcasts>

          <message name="testFunction" />

     </broadcasts>

</event-handler>

and my controller function:

<cffunction name="testFunction" returnType="any" output="true" >

     <cfargument name="event" type="any" required="true">

          <cfset justtest = 1>

     <cfreturn justtest>

</cffunction>   

I am using prootype as my ajax library.

I want to have myresult value as 1 according to the above scenario.

Pls help. Thnx for any help.

    This topic has been closed for replies.

    1 reply

    ajithman
    ajithmanAuthor
    Inspiring
    August 6, 2009

    By the way ,

    When i alert the responseText i am getting null value. Is this bcoz i have not included the view part in the event handler? If i included the view page then i wud have to create a new page which i dont want to do. Is it possible to get just a server value by ajax call without rendering any view?

    ajithman
    ajithmanAuthor
    Inspiring
    August 10, 2009

    Looks like no one was able to answer my query. However I was able to return a value without rendering a view, but for that i had to break the MG architecture.

    I made some modifcation in my controller function:-

    <cffunction name="testFunction" returnType="any" output="true" >     
    <cfargument name="event" type="any" required="true">       

    <cfset justtest = 1>

    <CFCONTENT TYPE="text" RESET="Yes"><CFOUTPUT>#serializeJSON(justTest)#
    <cfset request.modelGlueSuppressDebugging = true />
    <cfsetting showdebugoutput="false" /></CFOUTPUT><cfabort>

    </cffunction>

    Here the cfcontect acts as my view.