Я не получаю значения от textContent - PullRequest
0 голосов
/ 23 апреля 2020

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);
        }
      });
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...