2 Replies Latest reply on May 5, 2014 9:14 PM by Shraddha Prajapati

    Ajax call method which return json Data

    Shraddha Prajapati Level 1

      Hi, I make one function , which i want to return json value , for this which return type i mention in function:

       

      This is javascript which call Retrieve method.

      <script>

      debugger;

               var remoteDatasource = new kendo.data.DataSource({

                   transport: {

                       read: {

        type:"POST",

        url: "Controllers/Home.cfc",

        dataType: "json",

                           data: {

        method: "Retrieve",

                               dataLists: JSON.stringify(request)

                           }

                       }

                   },

      </script>

      Home.cfc

      component

      {

      remote   function Retrieve(string dataLists)

        {

        try

        {

                  q = new Query();

                  q.setsql("SELECT * FROM Product");

                  qResult = q.execute().getresult();

                  col_len = ListLen(qResult.Columnlist);

                  dataArray = ArrayNew(1);

                  row = 0;

                  col = 0;

                  for(row = 1; row <= len; row++)

                  {

                       for(col = 1; col <= col_len; col++)

                       {

                            FieldName = ListGetAt(qResult.Columnlist, col);

                            dataArray[row][col] = qResult[FieldName][col];

                       }

                  }

            jsonvar=serializeJSON(dataArray);

        }

        catch(any e)

        {

        }

      return jsonvar;

        }

      }