0

My View contain this code:

jQuery.ajax({
data:  "val"= + val,
dataType: 'script',
ype: 'post',
url: "/portfolio/update"
 );

In my controller I have this code:

j=params[:"val"]
h=j.split(" ")

Now I am getting this in my rails console: Parameters = {"val"=>" Default id3 id4 id5 test1 test2 fro "} and j is a nil class.
Any guesses why i am not receiving value in controller. I just started with fronted.

1 Answer 1

1

Try sending your data as an object as follows:

jQuery.ajax({
  data: { val: $.toJSON(val) },
  dataType: 'script',
  type: 'post',
  url: "/portfolio/update"
);

Then in your controller, access val parameter as follows:

j=params[:val]
Sign up to request clarification or add additional context in comments.

2 Comments

can You tell me how to call this function on button press in view?
@DeependerSingla, I'm sure you've already solved the "call this function on button press", if not you need to place this ajax call in the click handler of click event. Have a look at api.jquery.com/click. Also please add a comment here or post a new question if you run into any problems.

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.