S
S
Stanislav Somov2015-11-29 19:11:12
JavaScript
Stanislav Somov, 2015-11-29 19:11:12

What is the algorithm for changing css from python on the fly?

Web server on flask+jinja2. The page has several buttons. By clicking on which an ajax post is sent with data. The data in flask is processed and returned to the page. How can I change the display of the button and other page elements?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Somov, 2015-11-29
@DarkDemon

I will answer myself

$('#va1').click(function (e) {                                                                                                   
$.ajax({                                                                                                                       
      url: '/open1',                                                                                                             
      data: 'va1',                                                                                                               
      type: 'POST',                                                                                                              
      success: function(response) {                                                                                              
          if (response.text=="on") {$("#va1").css("background-image","url('/static/images/valve_h_blue.png')");}
          console.log(response);                                                                                                 
       },
       error: function(error) {                                                                                                   
            console.log(error);                                                                                                    
       }                                                                                                                          
});

@app.route('/open1', methods = ['POST'])                                                                                             
def open1():
    return jsonify({                                                                                                                 
        'text': 'on'
    })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question