2017-04-04 4 views
0

私のajaxリクエストに関する問題が残っています。 目的は、データベースを更新するために値を送信するためにクリックすることができるボタンまたはリンクを含む複数の行を含むテーブルを持つことです。これが行われた後、ボタンまたはリンクはもうクリック可能ではなく、特定の行の純粋なテキストに置き換えます。特定の行のテーブルでajax経由で変数値を送信する

編集:@Sagar Aroraのおかげで、特定の行の特定の変数値を送信する作業コードが用意されていますが、そのボタンをクリックしたことがわかるようにボタンを純粋なテキストに置き換える必要があります。私はすべてのために感謝しています

// the update database query and execution (is already doing fine) 

$request_id = $_POST['request_id']; 

echo "test $request_id test"; 

:私のglobal.jsで

// Several table-rows before and after 
// Problem is, the class "paid_button" also belongs to the other buttons in every other 
// table row, but I want to adress them specifically to get the id of that row for the ajax 

<td><button name="paid" value="<?php echo $id; ?>" class="paid_button">Bezahlt</button></td> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>       
<script src="../js/global.js"></script> 

$(document).on("click",".paid_button",function(){ 

var current_element = $(this); 
$.ajax({ 
type: "POST", 
url: "https://www.xxx", 
data: { 'paid': current_element.attr("value")}, 
success: function(data){ 
alert("ok"); 
this.attr("disabled","disabled");//this will disable the clicked button 
} 
}); 
}); 

updatePotatoe.php:

テストのために、私は次のようpotatoe.phpを持っていますヘルプとヒント!

+0

が私の答え.Thisはあなたの問題を解決しますを確認してください。 –

答えて

1

SOこの次のように:

<button name="paid" class="paid_button" value="$id" >Support</button> 

$(document).on("click",".paid_button",function(){ 

var current_element = $(this); 
    $.ajax({ 
    type: "POST", 
    url: "https://www.xxx.php", 
    data: { 'paid': current_element.attr("value")}, 
    success: function(data){ 
    alert("ok"); --> just for testing, I actually want to return values 
    this.attr("disabled","disabled");//this will disable the clicked button 
    } 
    }); 


}); 
+0

こんにちはサガー、助けてくれてありがとう!あなたの提案を元の投稿に編集し、コードをもう少し投稿しました。まだ何も起こらないが、ボタンをクリックしても何も起こらない:(。 – Franky2207

+1

@ Franky2207ちょっと警告(以下「何か」といいますか?)をクリックしてブラウザのコンソールにチェックインしても何かエラーが表示されますか? –

+0

私は次のエラー(警告がポップアップしない): 'SyntaxError:変数名がありませんvar this = $(this);'しかし、私は元々の問題を解決しましたが、私はまだテーブル行を一意に扱っています。可能ですか?オリジナルの投稿を編集しました。おやすみ! – Franky2207

関連する問題