将滑块值传递到瓶路线功能

问题描述 投票:1回答:1

我正在尝试运行代码,但是一部分无法正常工作,我需要从滑块传递值。我可以在html页面中看到该值,但无法将其传递给需要运行某些命令的inputRange()

我尝试仅隔离可与滑块一起使用的代码。您能否让我知道如何将滑块值传递给val_slide?谢谢。

代码:

from bottle import route, run, template

IP_ADDRESS = '192.168.0.80'
PORT = 8080

@route('/')
def hello():
    return '<b>Test</b>'

@route('/remote')
def remote():
    return '''<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script>
$(document).ready(function() {
  $('#inputRange').on('change mouseup', function(){
    var val_slide ='inputRange';
    $.ajax({
      url:  '/remote/inputRange',
      type: 'GET',
      data: {command:val_slide},
    });
  });
});
</script>
<style></style>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content">
<form>
<div style="text-align:center">
<label for="switch">Test</label>
<div class="slidecontainer">
<input id="inputRange" type="range" min="0" max="100" step="1" value="20"  class="slider" name='data'>
<output name="inputRange"/output>
</div>
</form>
</div>
</div>
</body>
</html>'''

@route('/remote/inputRange')
def inputRange():
    print val_slide
    # use val_slide value
    return 'inputRange'

try:
    run(host = IP_ADDRESS, port= PORT)
except(KeyboardInterrupt):
    print('Done!')
    quit()
python jquery ajax bottle
1个回答
1
投票

要从GET请求访问查询参数,您应该导入request并使用request通过名称访问值:

request.query

我不是JavaScript的专业专家,但据我所知,要发送实际值(而不仅仅是静态文本),您需要将request.query静态文本赋值替换为读取值:

from bottle import route, request

@route('/remote/inputRange')
def inputRange():
    val_slide = request.query.command
    print(val_slide)
    return val_slide
© www.soinside.com 2019 - 2024. All rights reserved.