skip to Main Content

I built a SessionMgr.cfc

<cffunction name="jgetValue" access="remote" returntype="string" output="yes" returnFormat="json">
    <cfargument name="variablename" type="string" required="yes">
    <cfset var result = 0>
    <cfset result = Evaluate("session" & "." & arguments.variablename)>
    <cfset var ReturnValue = result />
    <cfreturn result />
</cffunction>

in coldfusion to set/get session variables to run all my $.ajax calls, And I seem to be doing something wrong. I have read and read stackoverflow and every page google can produce on the subject, perhaps someone here can explain what I am doing wrong.

here is my getter();, my getValue(), and getCalBack();, the correct value is correct in getValue() but everything I have tried returns [object Object] to the getCAllBack() handler;
here is my code;

// rID in this instance is session.rID
var tReportID = getValue('rID');
alert(tReportID);

function getValue(a) {  
    return $.ajax({
                url: "cfc/SessionMgr.cfc",
                type: "get",
                dataType: "text",
                data: {
                    method: "jgetValue",
                    variablename: a
                },
              success: function(response) {
                  obj = JSON.parse(response);
                  //alert('in getValue: ' + obj);
                  console.log('getValue: ' , a , ' value: ' , JSON.parse(response));
              },
              error: function(msg) {
                  console.log(msg);
              }
          });
    //alert(' in returnVal: ' + obj);
 }

any help would be appreciated.
So I updated the code to your suggestion Prince, however I still get [object Object] in the alert.

If I breakdown the object, how do I get the responseText out? it has the right value; responseText: “12”

2

Answers


  1. Chosen as BEST ANSWER

    use cfajaxproxy instead

    <cfajaxproxy cfc="CFC/SessionMgr"       jsclassname="SessionMgr" />
    

    then in

    <script>
    var s = new SessionMgr();
    s.setValue('rID', x);
    ReportID = s.getValue('rID');
    </script>
    

  2. Try changing:

    dataType: "text",
    

    to:

    dataType: "json",
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search