Data passed by datatables to my ColdFusion update CFC

Data passed by datatables to my ColdFusion update CFC

BudHines2BudHines2 Posts: 6Questions: 2Answers: 0

i purchased data tables a few days ago. I am using ColdFusion and the bootstrap example and I was able to get the demo running pretty quickly thanks to Summer Wilson's posts including this one: http://coldfusionbeyond.com/post.cfm/replacing-cfgrid-with-datatables-part-3-editable-grids.

I am having an issue the data passed with the insert and update processes after I click update on the modal form. The data that is sent looks like this:
action edit
data[extn] 5797
data[first_name] Angelica
data[job] Chief Executive Officer (CEO)
data[last_name] Ramos
data[office] London
data[salary] 1200000
data[start_date] Tue, 1 Sep 20
id row_25

My ColdFusion application can read the action and id fields with no issue. However, it is looking at the datafields as an array. When I tried to process them as an array I get a java language issue.

My question is how can I remove data[ ] from the field names so they show as extn, first_name, etc.?

thanks,
Bud

This question has an accepted answers - jump to answer

Answers

  • BudHines2BudHines2 Posts: 6Questions: 2Answers: 0

    I was able to resolve the issue above by looping through the form fields and removing data[ and ] in the form fields so ColdFusion does not think these fields are part of an array. I take it that PHP users do not experience this same problem. If you do experience this same issue then be sure to speak up.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Hi,

    PHP and a number of other server-side environments will automatically convert HTTP parameters of that style into arrays / objects. .NET and ColdFusion appear to not be at all interested in doing that!

    There are a few options therefore:

    1) Use ajax.data to flatten the data to the top level object:

    ajax: {
      url: ...,
      data: function ( d ) {
        $.extend( d, d.data );
        delete d.data;
      }
    }
    

    2) Use ajax.data to send JSON to the server in the request body (this is what .NET appears to like):

    ajax: {
      url: ...,
      data: function ( d ) {
        return JSON.stringify( d );
      }
    }
    

    The long and short of that is that you can use ajax.data to manipulate the data that is being sent to the server!

    Regards,
    Allan

  • BudHines2BudHines2 Posts: 6Questions: 2Answers: 0

    Allan,

    Thanks for this information. I will give this a try. Much appreciated.

    Bud

This discussion has been closed.