N
N
nepster-web2014-05-25 23:58:28
JavaScript
nepster-web, 2014-05-25 23:58:28

How to specify property name in JSON data?

there are 2 variables. csrf field name and value, i.e. token:

var csrf_param = $('meta[name=csrf-param]').attr("content");
var csrf_token = $('meta[name=csrf-token]').attr("content");

This case needs to be transferred to the server:
var data = {'Свойство':'Значение'};
I did something like this:
var data = {csrf_param:csrf_token};
But at the output I got
{csrf_param:значение токена};
That is, instead of csrf_token, a value was substituted, everything is correct, but
csrf_param was written like that, but its value is needed.
Please tell me how this can be done.
Example for clarification:
var csrf_param = '_csrf';
var csrf_token = 1234567;

 var data = {csrf_param:csrf_token};

// как получается:
{csrf_param:1234567}

// как должно быть:
{_csrf:1234567}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Petrov, 2014-05-26
@nepster-web

var data = {}
data[csrf_param] = csrf_token

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question