Whats the best way to accomplish the following:
I have a slider, le开发者_如何学编程ts say when it's all the way to the left its value is 0 and when it's all the way to the right, its value is 10.
When the mouse is released I want to send the 10 into a function in a model, and instantly return a value from the model back into the view - without refreshing the page.
I can handle the javascript slider, what I'm curious about is how to make a remote form that can accomplish this, and just return the value without posting a new record to the database?
Thanks
you'll need to use ajax in some flavor to send the data to a controller method which will get your model instance from the db and send whatever information you need back to the client
add a js function to send the slider value and receive the response using ajax, for example using jquery:
function updateSlider(sliderVal){
$.post('/some-url', {value: sliderVal}, function(data) {
// data here is value returned by the server
});
}
call the above function in mouseup event or something depending how the slider works.
also in your controller use something like render :text => value
精彩评论