How to pass the javascript value as json object to the controller in ruby on rails?

前端 未结 2 1012
执笔经年
执笔经年 2021-01-19 20:06

I have got a task to do knockout.js using ruby on rails. I want to send the javascript value to the controller. My index.html.erb is

<%= javascript_inclu         


        
相关标签:
2条回答
  • 2021-01-19 20:17

    Any ajax http call will do.

    $.ajax({
      url: myUrl,
      dataType: 'json',
      async: false,
      data: myData,
      success: function(data) {
        //stuff
      }
    });
    

    or

        $.getJSON(muUrl, myData, function(data) {
      //stuff
    });
    
    0 讨论(0)
  • 2021-01-19 20:22

    Just try this.

     $.ajax({
          url:'/employees/<%=@employee.id%>',
          dataType: 'json',
          data: { passval: dataToSave},
          success: function(msg) 
               { 
    
               }
           });
    

    you can use the variable passval in the ajax page for retrieving the value of dataTosave,
    and the variable msg will return the response from the ajax.

    0 讨论(0)
提交回复
热议问题