• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Ajax call method which return json Data

New Here ,
May 04, 2014 May 04, 2014

Copy link to clipboard

Copied

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;

  }

}

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 05, 2014 May 05, 2014

Copy link to clipboard

Copied

One can see immediately that you have to make the following corrections, at least:

  1. Give the query a name;
  2. Point the query to a datasource;
  3. Define the variable 'len' (even better, use a different, less confusing, name for the variable).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2014 May 05, 2014

Copy link to clipboard

Copied

LATEST

ok i done the change...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation