A
A
Anton Misyagin2016-06-29 08:23:57
JavaScript
Anton Misyagin, 2016-06-29 08:23:57

How to set a key in a CoffeeScript data structure?

$.ajax
      url: '/мой/урл'
      method: 'POST'
      headers: {
        Accept : 'text/xml, text/html; charset=utf-8'
      }
      data: {id: id,
       'g-recaptcha-response': recaptchaResp}
      success: (result)->
        button.html result
        captchaBtn = button......

SyntaxError: [stdin]:179:27: unexpected :

Swears at 'g-recaptcha-response' : recaptchaResp
If I remove the comma:
data: {id: id
   'g-recaptcha-response': recaptchaResp}

then the javascript is wrong:
data: {
          id: id({
            'g-recaptcha-response': recaptchaResp
          })
        },

In general, the output needs such a javascript:
...
headers: {Accept : 'text/xml, text/html; charset=utf-8'},
data: {id: id, 'g-recaptcha-response': recaptchaResp},
success: .....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2016-06-29
@alexey-m-ukolov

This is how it should work:

data: {
    id: id,
    'g-recaptcha-response': recaptchaResp,
}

Or like this:
UPD: no, such options are not parsed normally. That 's how it works though.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question