[英]pass jquery variable to php page and receive calculated variable to first page
我有一個生成的表,當我按第6列上的按鈕以獲取行中的第一個單元格值並將其發送到覆蓋頁面時,我需要用它進行一些計算,這需要一些時間並顯示一個分數,我想用該分數替換第六列按鈕。
我無法在處理時讓page2.php顯示在疊加中(我從這里使用彈出窗口)
這是我到目前為止所達到的
<tbody>
<?php foreach ($rows as $row_number => $columns): ?>
<?php
$row_class = 'row-' . ($row_number + 1);
if ($row_number == 0) {
$row_class .= ' row-first';
}
if (count($rows) == ($row_number + 1)) {
$row_class .= ' row-last';
}
?>
<tr class="<?php print $row_class; ?>">
<?php foreach ($columns as $column_number => $item): ?>
<td class="<?php print 'col-'. ($column_number + 1); ?>" >
<?php print $item; ?>
</td>
<?php endforeach; ?>
<td>
<?php print $dnsearch; ?>
</td>
<td>
<button id="my-button">Get Score</button>
<div id="element_to_pop_up">
<a class="bClose">x<a/>
這里應該page2.php從腳本中接收變量並進行處理並返回數據(分數)以替換單擊的按鈕
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">
$(":button").click(function (e) {
e.preventDefault();
$('#element_to_pop_up').bPopup();
$.post("page2.php", {val: $(this).closest('tr').find('td:eq(0)').text()}, function(returned_data){
// alert(returned_data);
$(e.target).closest("td").text(returned_data); // to replace button with score
});
});
</script>
單擊按鈕后,將第一行的值發送給jquery並對第二頁進行ajax調用,並通過第二頁的響應進行所需的計算(將按鈕替換為結果以查找示例)。
http://api.jquery.com/jQuery.ajax/
將您的按鈕放在這樣的范圍內
<span id="result">
<button id="my-button">Get Score</button></span>
然后在您的響應處理jQuery中放這個
$("#result").html(you calculation result jquery variable);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.