代码之家  ›  专栏  ›  技术社区  ›  metrallador10

我没有从textContent获取值

  •  0
  • metrallador10  · 技术社区  · 6 年前

    var cardnumber = $(obj).siblings('.realnumber').textContent; 我不知道为什么,因为它确实有一些价值。当我在python中得到数据时,它说数据是空的。谢谢你的帮助。

    @app.route('/deleterow/', methods=['POST'])
    def deleterow():
        data = request.get_json()
        print(data)
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute("DELETE FROM carddetails WHERE CardNo = %s AND UID = %s", (data['number'], session['id']))
        mysql.connection.commit()
        return jsonify(status="success", data=data)
    
        <table id="UserCards">
      <tr>
        <th width=20%><strong>Card Holder</strong></th>
        <th width=20%><strong>Card Number</strong></th>
        <th width=10%><strong>Expiry Date</strong></th>
        <th width=10%><strong>CVC</strong></th>
        <th width="5%"></th>
      </tr>
      {% for row in rows %}
          <tr>
            <td id="name">{{ row['CardName']}}</td>
            <td id="number">****************</td>
            <td class="realnumber" style="display:none;">{{ row['CardNo'] }}</td>
            <td id="date">{{ row['CardExpDate'] }}</td>
            <td id="code">***</td>
            <td><a href="#" class="delete-row" onclick="deleteThis(this)"><span class="fas fa-trash-alt"></span></a></td>
          </tr>
      {% endfor %}
    </table>
    
     function deleteThis(obj){
          var cardnumber = $(obj).siblings('.realnumber').textContent;
          $(obj).closest('tr').remove();
          $.ajax({
            type: 'POST',
            url: "{{ url_for('deleterow') }}",
            contentType: "application/json",
            data: JSON.stringify({ number: cardnumber }),
            dataType: "json",
            success: function(response){
              window.location.href = 'http://127.0.0.1:5000/Drunkfy/Home/Paymentdetails';;
            },
            error: function(error){
                console.log(error);
            }
          });
        }
    
    0 回复  |  直到 6 年前