0

In application.js :

function get_cell_id(select_id)
{
  $.ajax({
      url: "/assign_variable",

      type: "GET",
       data:{channel:"abc"},
      error: function(){     
      alert('fail')
      }
  });
}

in static_pages_controller

def assign_variable
  @Four_Season_Set_Channel= params[:channel]
  end

in routes.rb

 match '/assign_variable', to:'static_pages#assign_variable', via: 'Get'

but i got alert fail, please help me fix it.

3
  • Which Rails version are you using? Commented Nov 25, 2013 at 7:39
  • Check your console for what error is happening at the rails end ... Commented Nov 25, 2013 at 7:45
  • it said : 500 internal server error Commented Nov 25, 2013 at 7:49

1 Answer 1

1

You might need to be rendering something, be it HTML/plain-text. That should solve the problem. Else you would be getting a 204 error (NO CONTENT). Also, in the javascript-error-function, try alert/log the error-code. That will help too.

Sign up to request clarification or add additional context in comments.

6 Comments

tks, can you tell me how can I display @Four_Season_Set_Channel in view ?
Honestly,that's a bad question. I have no clue on that the @Four... is all about, neither the requirement. From what I see, you are sending across a hard-coded value "abc" to the server. And in the controller, what do you intent to do?
I send data from js and want to assign it to ruby-variable, finally, i want to show it to sure that data is assigned.
OK. Looks like you are simply playing-around/learning. In the controller, use the code in gist.github.com/satyatechsavy/7637946#file-stackoverflow-help . Also, in the JS, add one more parameter "dataType" and the value to "script". This means, your ajax request is expecting a Javascript as a response. And in the controller, you are sending a JS-response to ALERT the value.
I did what you say and "page.alert @Four_Season_Set_Channel " doesn't work.
|

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.