Skip to main content
Inspiring
August 23, 2013
Question

pass coldfusion data to jQuery DatePicker using jQuery.get()

  • August 23, 2013
  • 8 replies
  • 2638 views

I use following jQuery code to pass json data from ColdFusion  using jQuery.get() to datepicker.

I tested the server side and it returns data without error.

I got 'I am here' and 'Data Loaded:" message from alert.

The click evnet is triggered, but it does not go in to success callback function.

Any information and help is great appreciated,

Regards,

Iccsi,

Her is client side coe:

jQuery("#btnTest").click( function() {
   alert(' I am here');
     jQuery.get({

        url: 'MyServer.cfc?method=MyMethod&vMyNumber=5',
        datatype: 'json',
        success: function(data)
       {
       alert(" i am inside");
       jQuery("#MyDate").datepicker('setDate', data.MyDate);
       console.log( data );
                             }
      });
    alert("Data Loaded: ");
    });

here is ColdFusion Server  side code:

<cffunction name="MyMethod" access="remote" returnformat="json">
 
  <cfargument name="vMyNumber" required="yes" default="0" hint="My Number">
  <cfargument name="page" required="no" default="1" hint="Page user is on">
  <cfargument name="rows" required="no" default="10" hint="Number of Rows to display per page">
  <cfargument name="sidx" required="no" default="" hint="Sort Column">
  <cfargument name="sord" required="no" default="ASC" hint="Sort Order">

<cfset var Mydata = ArrayNew(1)>

<cfset start = ((arguments.page-1)*arguments.rows)+1>
<cfset end = (start-1) + arguments.rows>
<cfset i = 1>


<cfstoredproc procedure="mySP">
<cfprocparam value = "#vMyNumber#" CFSQLTYPE = "cf_sql_integer">
<cfprocresult name="MyProp" resultset="1">
</cfstoredproc>


<cfloop query="MyProc" startrow="#start#" endrow="#end#">

       <cfset Mydata = [#MyNumber#,#MyDate#]>

            <cfset i = i + 1>           
  </cfloop>

     <cfset totalPages = Ceiling(MyProp.recordcount/arguments.rows)>
     <cfset stcReturn =     {total=#totalPages#,page=#Arguments.page#,records=#MyProp.recordcount#,rows=#Mydata#}>
       

<cfreturn stcReturn>


</cffunction>

Here is data returned from ColdFusion Server.

{"ROWS":[[6,"May, 03 2002 00:00:00"]],"PAGE":1,"RECORDS":1,"TOTAL":1.0}

    This topic has been closed for replies.

    8 replies

    p_sim
    Participating Frequently
    August 24, 2013

    First off all, when you declare a local variable in a function, use "var" scope. This will prevent problem in the future when your app gets bigger and somewhere you use the same variable names.

    Now, let's talk about the jQuery.

    1. Why you use .get() method? It is critical that you know what you are doing since this problem is very similar to the one that you had before.

    2. .datepicker('setDate', data.MyDate); -- Where does .MyDate refer to?

    3. It would be wise that you make sure your document is ready before allowing user clicking something.

    iccsiAuthor
    Inspiring
    August 24, 2013

    Thanks for the message and help,

    I have my jQuery.get() in jQuery(document).ready  function.

    MyDate is the field return from cffunction in myData.

    MyData returns MyNumber and MyDate.

    I see jQuery web site to refer the field using this period.

    The previous issue is the data, I tried many browsers and play with data and learned that modify data change the behavior of the jqGrid.

    I deleted some data then jqQuery works,

    I plan to create a brand new form just one cfc with one function to run specific stored procedure and one date picker on the form to see does it work or not.

    Thanks again for helping,

    Regards,

    Iccsi,