我正在使用这个函数尝试向服务器发出请求。我想知道如何在 Rails Controller 中获取 Jquery Ajax 发送的数据。
function addnote(){
$.ajax({
type: "POST",
url:SERVER_URL+"api/addNotes/",
data: {note_text: $('#note_text').val(), note_lat: $('#lat').val(), note_lng: $('#lng')},
success: function(data, textStatus, jqXHR) {
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error=" + errorThrown);
}
});
这是我的 rails Controller
def add_notes
end
结束
最佳答案
在 Rails Controller 中
def add_notes
note_text = params[:note_text]
note_lat = params[:note_lat]
note_lng = params[:note_lng]
end
关于ruby-on-rails - 如何从 Jquery Ajax 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10847150/