Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ajax将图像文件发送到python(flask)_Javascript_Jquery_Python_Ajax_Flask - Fatal编程技术网

Javascript 使用ajax将图像文件发送到python(flask)

Javascript 使用ajax将图像文件发送到python(flask),javascript,jquery,python,ajax,flask,Javascript,Jquery,Python,Ajax,Flask,我的网站上有一个图像每5秒钟更新一次(使用PubNub和Raspberry Pi。我使用JavaScript更新图像源)。这个很好用。我的问题是,我试图使用Ajax将源文件发送到python(flask)并将该文件存储在MySQL数据库中。然后我想在网站上显示文件名。我不熟悉java脚本/ajax 以下是我的java脚本: <script type=text/javascript> $(function() { $('img#imageid').bind( f

我的网站上有一个图像每5秒钟更新一次(使用PubNub和Raspberry Pi。我使用JavaScript更新图像源)。这个很好用。我的问题是,我试图使用Ajax将源文件发送到python(flask)并将该文件存储在MySQL数据库中。然后我想在网站上显示文件名。我不熟悉java脚本/ajax

以下是我的java脚本:

<script type=text/javascript>
    $(function() {
        $('img#imageid').bind( function() {
            $.getJSON('/_button', {
                proglang: document.getElementById('imageid').src,
            }, function(data) {
                $("#buttonState").text(data.result);
            });
        });
    });
</script>
为什么不直接发布图片呢?您可以使用WebSocket来完成此操作,但安装和工作需要更多的时间。为什么不发布图像呢?您可以使用WebSocket来实现这一点,但安装和工作需要更多的时间。
<img id="imageid" src="http://searchengineland.com/figz/wp-content/seloads/2015/12/google-amp-fast-speed-travel-ss-1920-800x450.jpg">
<form>
    <p>The button is <span id="buttonState"></span></p>
    <br>
</form>
@app.route("/_button")
def _button():
    try:
        lang = request.args.get('proglang')
        c.execute ("""UPDATE pictures SET file_name=%s WHERE user_id=%s""",
                                       (str(lang), str(session['user_id'])))
        return jsonify(buttonState=lang)
    except Exception as e:
        return render_template("500.html", error = str(e))