I have a tree structure where on hover of the user image it should show some of other user related info but instead of show that info in proper div, its show raw HTML data.
HTML Code
there can be n number of a href
<a href="{{ route('user-binary-tree',[ 'eUserID' => $ERight12]) }}" class="bt-element binary-tree-on-hover" id="{{$ERight12}}">
<img class="rounded-circle" style="width: 50px" src="{{ asset($packageImg) }}">
{{ $Right12[0]->sponsor_code }}
</a>
JavaScript code
$('.binary-tree-on-hover').mouseover(function() {
var userId = this.id;
var $this = $(this);
$.ajax('/binary-tree-ajax/' + userId + '/html', {
method: "GET",
dataType: "html",
success: function(data) {
$this.attr('title', data).mouseover(); //HTML DATA SHOW IN HOVER
}
});
});
Ajax response is
<div class="bt-details">
<table class="table color-table inverse-table">
<thead>
<tr>
<td class="text-center" style="font-size: 100%">Chethan k Test</td>
<td class="text-center" style="font-size: 100%"></td>
<td class="text-center">
<span class="btn btn-danger btn-xs btn-outline" style="border-width: 2px;">Inactive</span>
</td>
</tr>
<tr>
<td class="text-center" style="font-size: 100%">Sponsor ID</td>
<td class="text-center" style="font-size: 100%" colspan="2">UNO187175</td>
</tr>
<tr>
<td class="text-center" style="font-size: 100%">Binary Qualified</td>
<td class="text-center" style="font-size: 100%" colspan="2">
<span class="btn btn-danger btn-xs btn-outline" style="border-width: 2px;">No</span>
</td>
</tr>
<tr>
<th width="40%" class="text-center">Position</th>
<td class="text-center" style="font-size: 95%">Left</td>
<td class="text-center" style="font-size: 95%">Right</td>
</tr>
</thead>
<tbody>
<tr>
<th width="40%" class="text-center">Downline</th>
<td class="text-center">39</td>
<td class="text-center">6</td>
</tr>
<tr>
<th width="40%" class="text-center">Business</th>
<td class="text-center">$0</td>
<td class="text-center">$0</td>
</tr>
<tr>
<th width="40%" class="text-center">Carry</th>
<td class="text-center">$0</td>
<td class="text-center">$0</td>
</tr>
<tr>
<th width="40%" class="text-center" rowspan="2">Binary Generated</th>
<td class="text-center" style="font-size: 95%">Last Day</td>
<td class="text-center" style="font-size: 95%">Till Date</td>
</tr>
<tr>
<td class="text-center">$0</td>
<td class="text-center">$</td>
</tr>
</tbody>
</table>
When i hover on any of the user image its shows row HTML data instead of proper div as seen in 1st image
Also its keep calling the Ajax request infinite times but when i remove $this.attr('title', data).mouseover(); its called Ajax request only once. so i think the infinite calling happening because of this line only.
here how its shows
but i want to show like this
Note : 2nd one is working but its not ajax call and it will fetch all the user info from controller and load on view hence when user increase it will slow down the page so i am trying to call ajax on hover of the image.
End up with using popover function
HTML Code
<div id="popover_html" style="display:none;">
hover_data
</div>
JavaScript Code
jQuery('.binary-tree-on-hover').popover({
title: popoverContent,
html: true,
placement: 'bottom',
trigger: 'hover'
});
function popoverContent() {
var content = '';
var element = $(this);
var id = element.attr("id");
var APP_URL = "{{ url('/')}}";
const adminRoutePrefix = $("#admin_route_prefix").text();
$.ajax({
url: APP_URL + '/' + adminRoutePrefix + '/networks/binary-tree-ajax/' + id + '/html',
method: "GET",
async: false,
// dataType: "HTML",
success: function(data) {
content = $("#popover_html").html();
content = content.replace(/hover_data/g, data);
}
});
return content;
}
Related
I'm currently using Codeigniter and using Ajax to post my search result through the server and result the result and display on my responsive datatable. However the result was not added into my datatable and i even try to add it with .append but it just added below my table and the search function on datatable is not searching it and it still show "No data available in table".
Here are my View :
<div id="reporting" class="container">
<h3 class="section-title">Export Time Location Panel</h3>
<form id = "search">
<div class="form-group">
<div class="form-group">
<h5>Date/ Time</h5>
<input type="datetime-local" name="datetime" id = "datetime">
<?php echo form_error('datetime'); ?>
</div>
</div>
<button type="submit" class="btn btn-primary">Confirm</button>
</form><br/>
<table class="table table-bordered table-light" >
<thead>
<tr>
<td class="id">ID</td>
<td class="na">NA Name</td>
<td class="centre">Centre Name</td>
<td class="login">Date & Time</td>
<td class="lat">Latitude</td>
<td class="long">Longtitude</td>
<td class="accuracy">Accuracy</td>
<td class="place">Location Name</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<?php include('footer.php'); ?>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
var tbl = $('.table').DataTable({
responsive: true,
"order": [[0, "desc"]]
})
$( "#search" ).submit(function(event) {
event.preventDefault();
var value = $("#datetime").val();
$.ajax({
type:'POST',
url:'<?php echo base_url(); ?>location/search_record',
data:{'datetime':value},
success:function(data){
$('.table').append(data);
}
});
});
} );
</script>
Here are my Model :
public function search_record(){ //Display Record at View Page
$this->load->model('location_model');
$this->load->library('form_validation');
echo '
<tr>
<td class="id">ID</td>
<td class="na">NA Name</td>
<td class="centre">Centre Name</td>
<td class="login">Date & Time</td>
<td class="lat">Latitude</td>
<td class="long">Longtitude</td>
<td class="accuracy">Accuracy</td>
<td class="place">Location Name</td>
</tr>
';
}
You have to add data to table body by
success:function(data){ tbl.rows.add($(data)).draw(); }
Please check this link
https://jsfiddle.net/kuLcqwav/3/
https://datatables.net/examples/api/add_row.html
I want to create table like in this site:
https://www.avast.com/en-in/exploit-protection.php
I tried with below code but something is happening wrong , I am beginner of jquery.Reading data from mysql php to show.
HTML:
$(document).ready(function(){
$("#myTable tr:odd").addClass("odd");
$("#myTable tr:not(.odd)").hide();
$("#myTable tr:first-child").show();
});
$(document).ready(function(){
$("#myTable tr").click(function(){
$(this).next("tr").toggle();
$(this).find(".arrow").toggleClass("up");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id ='myTable' class='tablesorter' style='table-layout:fixed;'>
<thead>
<tr>
<th class='header' width='4%'>Wild</th>
<th class='header ' width='12%'>Release Date</th>
<th class='header' width='12%'>Exploit Name1</th>
<th data-sorter='false' width='18%'>Name2</th>
<th data-sorter='false' width='53%'>Comments</th>
<th data-sorter='false' width='1%'></th>
</tr>
</thead>
<tbody>
<tr>
<td> <i hidden>1</i><img src='ex.png' alt='' border=3 height=25 width=25></img>
</td>
<td>03/11/2015</td>
<td><b> CVE-2015-1623</b></td>
<td style='word-wrap:break-word;'>
<ul>
<li>ABC</li>
<li>XYZ</li>
<li>PQR</li>
</ul>
</td>
<td style='word-wrap:break-word;'>
Microsoft Internet Explorer 11 allows remote attackers to execute arbitrary code or cause ...
</td>
<td>
<div class='arrow'></div>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<b>Link: </b>
<ul>
<li><a href =http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-1623 target ='_blank'>http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-1623<br></a></li>
</ul>
</td>
<td></td>
</tr>
<tr>
Please let me know what is wrong in jquery.
I am having a table with 7 columns(Complaintid id,name,school name etc...) and also have button. When I click the button I need to pass the complaintid of that row to another page. pls help me find a way to pass the value.
<html>
<body>
<?php
include '../library/dbconnect.php';
$query="SELECT * FROM Complaint_register WHERE status=1 ORDER BY entrydate ";
$result=mysql_query($query) or die("Selection query of
Complaint_register is Error ".mysql_error());
$num = mysql_numrows($result);
$i=0;
$j=1;
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
$date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];
?>
<tr>
<td style="color: #000000"><?php echo $j;?></td>
<td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
<td style="color: #000000"><?php echo $entrydate;?></td>
<td style="color: #000000" ><?php echo $row[studname];?></td>
<td style="color: #000000"><?php echo $row[District];?></td>
<td style="color: #000000"><?php echo $row[School_name] ;?></td>
<td style="color: #000000"><?php
echo $row[Standard]."-".$row[Division];?></td>
<td id="disp" ><?php echo $row[Complaint];?></td>
<td id="button" name="viewbutton" >
</td>
</tr>
<?php
$button++;
$j=$j+1;
}
?>
</table>
</form>
</body>
</html>
Instead of using
<td id="button" name="viewbutton" >
</td>
use,
<td>
<input type="button" onclick="functionname(<?php echo $row[complain_Id]; ?>)">
</td>
and add a javascript function
<script>
function functioname(param)
{
window.location="redirectionpage?id="+param;
}
</script>
This will redirect to the page redirectionpage with the id.
Few Loop holes in your current attempt.
Strictly use mysqli or PDO instead of mysql as it's been deprecated.
It's mysql_num_rows not mysql_numrows.
Now coming to your problem, you can solve this by using jQuery ajax.
$("table").on("click","#button",function(){
var cid = $("#disp").text();
$.ajax({
type: "GET",
url: "anotherpage.php",
data: { complainid: cid},
success: function(data) {
alert(data) //To check if response is success
}
});
});
anotherpage.php:
<?php
$cid = $_GET['complainid'];
?>
You can use a link with complain id like complaints.php?complainid=echo your value here
<td id="button" name="viewbutton" >
view complaint
</td>
and you can style that link like a button if needed.
In complaints.php page you can take the details of that complain with the id you passed.
I am new with java script. The code I have for deleting table row works fine when table already exists in the page but it doesnt work if I load table from another page by ajax call.. please help me to solve this.. java script is here
$(document).ready(function()
{
$('table#delTable td a.delete').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var id = $(this).parent().parent().attr('id');
var data = 'id=' + id ;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete_row.php",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
// style the table with alternate colors
// sets specified color for every odd row
$('table#delTable tr:odd').css('background',' #FFFFFF');
});
html code
<table id="delTable">
<tr id="ripon">
<td align="left">Ipsum</td>
<td align="center">19</td>
<td align="center">17</td>
<td align="center"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></td>
</tr>
<tr id="rukon">
<td align="left">Dolor</td>
<td align="center">55</td>
<td align="center">12</td>
<td align="center"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></td>
</tr>
<tr id="sumon">
<td align="left">Sit</td>
<td align="center">11</td>
<td align="center">18</td>
<td align="center"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></td>
</tr>
<tr id="mamun">
<td align="left">Amet</td>
<td align="center">29</td>
<td align="center">27</td>
<td align="center"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></td>
</tr>
The easiest solution for this is to use "Delegated Events".
For more information, see jQuery's on docs.
$("body").on("click", "table#delTable td a.delete", function(event){
// insert your code here
});
Note: while I called on on body, you can call it on something "closer" to the table, if it's going to be there when the page loads (or more specifically, when you make the on call).
I have an html file as coded below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.style1 {
background-color: #c3d9ff;
font-family:arial,sans-serif;
}
.style2 {
text-align: center;
font-weight: bold;
}
.style3 {
background-color: #FFFFFF;
font-family:arial,sans-serif;
text-align: center;
font-weight: bold;
}
.style4 {
background-color: #FFFFFF;
font-family:arial,sans-serif;
text-align: left;
}
body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:15px;
background-color: ;
}
.action_button {
font-weight:bold;
float:right;
}
</style>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">$(function() {
$('.action_button').click(function() {
var $button = $(this);
$.ajax({
type: 'POST',
url: 'action.php',
data: 'id='+ $(this).attr('id'),
cache: false,
success: function(result) {
var $row = $button.closest('tr');
var $col = $row.find('.clickme2');
$row.fadeOut('fast', function() {
if (result == 'ACTIVATED') {
$button.text('Activate');
$col.text('Active');
} else if (result == 'INACTIVATED') {
$button.text('Inactivate');
$col.text('Inactive');
}
}).fadeIn();
}
});
return false;
});
});
</script>
</head>
<body>
<table style="width: 90%" align="center" class="style1">
<tr>
<td colspan="7" class="style2">MANAGER</td>
</tr>
<tr>
<td class="style3" style="width: 139px">Col1</td>
<td class="style3" style="width: 139px">Col2</td>
<td class="style3" style="width: 139px">Col3</td>
<td class="style3" style="width: 139px">Col4</td>
<td class="style3" style="width: 139px">Col5</td>
<td class="style3" style="width: 200px">Col6</td>
<td class="style3" style="">Action</td>
</tr>
</table>
<td id="main" class="main">
<td class="update">
<table style="width: 90%" align="center" class="style1">
<tr>
<td class="style4" style="width: 139px">DataA1</td>
<td class="style4" style="width: 139px">DataA2</td>
<td class="style4" style="width: 139px">DataA3</td>
<td class="style4" style="width: 139px">DataA4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataA6</td>
<td>
<button href="#" id="DataA1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataB1</td>
<td class="style4" style="width: 139px">DataB2</td>
<td class="style4" style="width: 139px">DataB3</td>
<td class="style4" style="width: 139px">DataB4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataB6</td>
<td>
<button href="#" id="DataB1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataC1</td>
<td class="style4" style="width: 139px">DataC2</td>
<td class="style4" style="width: 139px">DataC3</td>
<td class="style4" style="width: 139px">DataC4</td>
<td class="style4 clickme2" style="width: 139px">Active</td>
<td class="style4" style="width: 200px">DataC6</td>
<td>
<button href="#" id="DataC1" class="action_button" style="width:80px;height:">
Inactivate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataD1</td>
<td class="style4" style="width: 139px">DataD2</td>
<td class="style4" style="width: 139px">DataD3</td>
<td class="style4" style="width: 139px">DataD4</td>
<td class="style4 clickme2" style="width: 139px">Active</td>
<td class="style4" style="width: 200px">DataD6</td>
<td>
<button href="#" id="DataD1" class="action_button" style="width:80px;height:">
Inactivate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataE1</td>
<td class="style4" style="width: 139px">DataE2</td>
<td class="style4" style="width: 139px">DataE3</td>
<td class="style4" style="width: 139px">DataE4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataE6</td>
<td>
<button href="#" id="DataE1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
</table>
</td>
</td>
</body>
</html>
The fage contain a table with 5 rows with a button at the end of the row. On click, the button submits data to a php file and then changes text and blurs according to the response from php file. The blur function and change text function in col5 is working well. But the change text function in button got really buggy. The button text should change accordingly. the text of button "Activate" should change to "Inactivate" and the text of button "Inactivate" should change to "Activate" on click / successful submission.. This is not working..
Below is the php file code
<?php
$id = $_POST[id];
if($id=="DataA1"){
echo "ACTIVATED";
}
if($id=="DataB1"){
echo "ACTIVATED";
}
if($id=="DataE1"){
echo "ACTIVATED";
}
if($id=="DataC1"){
echo "INACTIVATED";
}
if($id=="DataD1"){
echo "INACTIVATED";
}
?>
Thanks in advance.. :)
blasteralfred
I think your logic is wrong. When the button initially says "Activate", you are returning "ACTIVATED" so your button should then read "Inactivate." You are, however, setting the text to "Activate" again. Look at the button with id "DataA1" for an example.
Change $_POST[id] to $_POST["id"].
I found the solution..
Thank you #Heikki, #Cristy..... :)
I corrected the script as below
$(function() {
$('.action_button').click(function() {
var $button = $(this);
$.ajax({
type: 'POST',
url: 'action.php',
data: 'id='+ $(this).attr('id'),
cache: false,
success: function(result) {
var $row = $button.closest('tr');
var $col = $row.find('.clickme2');
$row.fadeOut('fast', function() {
if (result == 'ACTIVATED') {
$button.text('Inactivate');
$col.text('Active');
} else if (result == 'INACTIVATED') {
$button.text('Activate');
$col.text('Inactive');
}
}).fadeIn();
}
});
return false;
});
});
Thanks again ... :)
I know you've already solved the problem, but here's my answear anyway:
Replace
data: 'id='+ $(this).attr('id'),
with
data: 'val='+ $button.html(),
And, the php file with this:
<?php
$val = $_POST['val'];
if(strstr($val,"Activate"))
echo "ACTIVATED";
else
echo "INACTIVATED";
?>