1
我有臺這樣的如何爲表中的多個數據創建AJAX POST按鈕?
<table>
<tr>
<th>User</th>
<th>IP</th>
<th>Action</th>
</tr>
<tr>
<td>Jack</td>
<td>192.168.0.1</td>
<td><button id="check" name="192.168.0.1">Check</button></td>
</tr>
<tr>
<td>Eve</td>
<td>192.168.0.2</td>
<td><button id="check" name="192.168.0.2">Check</button></td>
</tr>
<tr>
<td>Smith</td>
<td>192.168.0.3</td>
<td><button id="check" name="192.168.0.3">Check</button></td>
</tr>
</table>
如何實現發送POST數據IP與AJAX? 我曾嘗試與此代碼,但不工作..
<script>
$('#check').click(function() {
var getIP = $('#check').name();
var dataIP = 'sendIP=' + getIP;
$.ajax({
url: 'url.php',
type: 'POST',
data: dataIP;
success: function() {
alert("Success");
}
});
});
</script>
[更新] 這是我的項目全部代碼。
<script>
$(document).ready(function() {
$('#reportrange span').on('DOMSubtreeModified', function() {
var dariRange = $(this).html();
var SplitRange = dariRange.split("~");
$('#datatable-keytable').DataTable({
"destroy": true,
"processing": true,
"keys": true,
"order": [[ 6, "desc" ]],
"ajax": {
url: "view.php",
type : 'GET',
data : {
datedari : SplitRange[0].trim(),
datesampai : SplitRange[1].trim()
}
},
"columnDefs": [
{ "width": "5%", "targets": 0 },
],
"columns": [
{ "data": "click_username" },
{ "data": "click_cid" },
{ "data": "click_offer" },
{ "data": "click_ip" },
{ "data": "click_isp" },
{ "data": "click_posttime" },
{ "data": "click_ip",
"render": function (click_ip,data,row) {
var clickid = data.click_cid;
return ('<center><button class="check" id="'+click_ip+'" name="'+clickid+'">Check</button></center>'); //This for Button check
}
},
],
});
});
});
</script>
<script type="text/javascript">
$(document).on('click', '.check',function() {
var dataID = 'sendCID=' + this.name;
var dataIP = this.id;
$.ajax({
url: 'send_data.php',
type: 'POST',
data: dataID;
success: function() {
window.open('http://whatismyipaddress.com/ip/'+dataIP);
}
});
});
</script>
我要發佈var dataID
到send_data.php
,然後如果成功打開新標籤頁中http://whatismyipaddress.com/ip/'+dataIP
但不與此代碼的工作,
我希望有人能幫我解決這個問題,謝謝
不行,順便說一句我使用數據表serverside。我在我的文章中更新了完整的代碼,請參閱 – Zayn
您可能需要使用事件代理。嘗試'$(document).on('click','.check',function(){...' – charlietfl
也不起作用,讓我看看我的帖子中的完整代碼 – Zayn