0

I have a Sinatra app and I'm updating some stuff in a mongoDB database with some PUT-requests.

In javascript, the actual values I'm posting are:

entity: {
    config: someString,
    parameters: parameterArray, // EMPTY [ ]
    dt: dtArray, // EMPTY [ ]
}

I'm doing this via jQuery ajax.

On the server side I get the following:

params[:entity] #=> config = someString

But the empty arrays are missing. Why is this? I need them! The same route will handle both empty arrays and no parameter at all in a different way...

MarioDS
  • 12,895
  • 15
  • 65
  • 121
  • 1
    Try this question: http://stackoverflow.com/questions/9397669/jquery-ajax-jsonp-how-to-actually-send-an-array-even-if-its-empty – cfs Jun 10 '13 at 13:13
  • @cfs I feared so much yes... Problem is it makes a huge difference in my app if it's an empty array or just nothing at all... – MarioDS Jun 10 '13 at 13:14
  • 1
    The first workaround that comes to mind is to add `parameterCount` and `dtCount` properties, and that way you can specify `0` for an empty array, but to represent "nothing" you'd either leave the `count` properties out or specify `null` or `-1`. (Then, in case it's not blindingly obvious, server-side you'd test the count properties first and decide what to do from there.) – nnnnnn Jun 10 '13 at 13:19
  • @nnnnnn I did something similar but I just had one element in the arrays, an empty string. – MarioDS Jun 10 '13 at 13:25
  • Cool. That's obviously fine as long as an empty string isn't an otherwise valid value. There're lots of variations on either idea... – nnnnnn Jun 10 '13 at 13:53

0 Answers0