/    Sign up×
Community /Pin to ProfileBookmark

How to pass dynamically generated anchor to ajax and then to php script?

My website is divided into two columns. On the left is sidebar which contains list of users dynamically generated from database, on the right-hand side should be unique chart generated by javascript framework (ajax) based on user_id. And this chart should be shown after choosing some user from list. The php file live-data.php which is used by this javascript/ajax needs GET parameter. Now it’s:

[CODE]url: “php/live-data.php”[/CODE]

and

[CODE]$.get(“php/live-data.php?Consultar=1”, function(UltimosDatos)[/CODE]

but it should be

[CODE]url: “php/live-data.php?user_id=2”[/CODE]

and

[CODE]$.get(“php/live-data.php?user_id=2&Consultar=1”, function(UltimosDatos)[/CODE]

Where 2 is user_id got after clicking some user name from dynamically generated list. The php script live-data.php is ready for GET variable and returns proper json for chart framwork (this javascript shown below). I dont know how to pass div id to this ajax code.

[B]HTML+PHP:[/B]

[CODE]<div id=”left” class=”pre-scrollable col-lg-3″>
<div class=”list-group”>
<?php include(“php/dbSettings.php”);
$result = $conn->query(“SELECT * FROM user ORDER BY user_id”);
if (!$result) {
die(mysqli_error($conn));
}
while ($user = mysqli_fetch_array($result)){
echo ‘<a href=”#’.$user[‘user_id’].'” data-toggle=”tab” class=”list-group-item”>’ . $user[‘firstName’] . ” ” .$user[‘lastName’] . ‘</a>’;
}
?>
</div>
</div>

<div id=”right” class=”col-lg-9″>
<div class=”tab-content”>
<?php include( “php/dbSettings.php”);
$result=$ conn->query(“SELECT * FROM users ORDER BY user_id”);
if (!$result) {
die(mysqli_error($conn));
}
while ($user = mysqli_fetch_array($result)){
echo ‘<div class=”tab-pane” id=”‘.$user[‘user_id’].'”>
<div id=”chart” style=”min-width: 310px; height: 400px; margin: 0 auto”></div>
</div>’;
} ?>
</div>
</div>[/CODE]

[B]Javascript/Ajax:[/B]

[CODE]<script>
$(function() {
$(document).ready(function() {
var ultimox;
var ultimoy;

$.ajax({
url: “php/live-data.php”, //i want this line to be “php/live-data.php?user_id=2” and 2 is variable got from user list onlick
type: ‘get’,
success: function(DatosRecuperados) {
$.each(DatosRecuperados, function(i, o) {
//some deleted code – unimportant
});

//some deleted code – unimportant

$(‘#chart’).highcharts({
//draws chart
});

}
});
});
setInterval(function() {
$.get(“php/live-data.php?Consultar=1”, function(UltimosDatos) { //i want this line to be “php/live-data.php?php/live-data.php?Consultar=1&user_id=2” and 2 is variable got from user list onlick
//updates chart
}
});
}, 1000);

//some deleted code – unimportant

});
</script>[/CODE]

I hope someone can help me on my way.

Thanks, Paul

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rootMay 27.2016 — Thats not ajaz, its JQuery which is written in JavaScript and the ajax you are using is just a wrapper of that in JQuery.

JQuery goes in the JavaScript Frameworks forum, see my sig.
×

Success!

Help @animashi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...