0

I am getting the following values to put into my JSON stringify method. I will use it for AJAX. The field_name variable can vary.

value = input.val()
parent = input.parent()
userId = parent.data().userid
field_name = parent.data().field

$.ajax "/api/users/#{userId}",
  method: 'PATCH'
  contentType: 'application/json'
  dataType: 'json'
  data: JSON.stringify( {user:{field_name:value}})
  success: (data) =>

However, the keys in {user:{field_name:value}} do not express variables. Only the value of the k-v pair can express variables. How can I make the key field_name use variables to be flexible for this?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.