Send AJAX request by clicking a link inside a dynamically created bootstrap accordion
I have a dynamically created accordion like this:
<div class="panel-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#1" class="tasktitle" data-id="1" id="opentask">$name</a>
</h5>
</div>
<div id="1" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#2" class="tasktitle" data-id="2" id="opentask">$name</a>
</h5>
</div>
<div id="2" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
</div>
</div>
Then I have a static value like $loggeduser which is always the same for the logged user.
As this is a dynamically created accordion though, the id of each accordion section is different
What I am trying to achieve is when the user click to open the accordion, in the same time to execute an AJAX request which will send the value of the $loggeduser together with the id of the accordion in which the clicked link is placed in.
This is the ajax I am using to send the info to the file
$(function(){
$("#opentask").click(function(){
$.get("markread-task.php?id=ID&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
but I cant figure out how to to have a different ID in this link
markread-task.php?id=ID&user=LOGGEDUSERCOMMENT
for example if the user click on the link that opend accordion 2, the ajax sends link like
markread-task.php?id=2&user=LOGGEDUSERCOMMENT
Thanks for your help
javascript jquery ajax
add a comment |
I have a dynamically created accordion like this:
<div class="panel-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#1" class="tasktitle" data-id="1" id="opentask">$name</a>
</h5>
</div>
<div id="1" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#2" class="tasktitle" data-id="2" id="opentask">$name</a>
</h5>
</div>
<div id="2" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
</div>
</div>
Then I have a static value like $loggeduser which is always the same for the logged user.
As this is a dynamically created accordion though, the id of each accordion section is different
What I am trying to achieve is when the user click to open the accordion, in the same time to execute an AJAX request which will send the value of the $loggeduser together with the id of the accordion in which the clicked link is placed in.
This is the ajax I am using to send the info to the file
$(function(){
$("#opentask").click(function(){
$.get("markread-task.php?id=ID&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
but I cant figure out how to to have a different ID in this link
markread-task.php?id=ID&user=LOGGEDUSERCOMMENT
for example if the user click on the link that opend accordion 2, the ajax sends link like
markread-task.php?id=2&user=LOGGEDUSERCOMMENT
Thanks for your help
javascript jquery ajax
We would need more code in order to help you here, there could be many possible solutions depending on how it's implemented.
– Armel
Jan 3 at 13:44
what else do you need ?
– lStoilov
Jan 3 at 14:40
add a comment |
I have a dynamically created accordion like this:
<div class="panel-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#1" class="tasktitle" data-id="1" id="opentask">$name</a>
</h5>
</div>
<div id="1" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#2" class="tasktitle" data-id="2" id="opentask">$name</a>
</h5>
</div>
<div id="2" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
</div>
</div>
Then I have a static value like $loggeduser which is always the same for the logged user.
As this is a dynamically created accordion though, the id of each accordion section is different
What I am trying to achieve is when the user click to open the accordion, in the same time to execute an AJAX request which will send the value of the $loggeduser together with the id of the accordion in which the clicked link is placed in.
This is the ajax I am using to send the info to the file
$(function(){
$("#opentask").click(function(){
$.get("markread-task.php?id=ID&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
but I cant figure out how to to have a different ID in this link
markread-task.php?id=ID&user=LOGGEDUSERCOMMENT
for example if the user click on the link that opend accordion 2, the ajax sends link like
markread-task.php?id=2&user=LOGGEDUSERCOMMENT
Thanks for your help
javascript jquery ajax
I have a dynamically created accordion like this:
<div class="panel-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#1" class="tasktitle" data-id="1" id="opentask">$name</a>
</h5>
</div>
<div id="1" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
<div class="panel panel-default" >
<div class="panel-heading">
<h5 class="panel-title small">
<a data-toggle="collapse" data-parent="#accordion" href="#2" class="tasktitle" data-id="2" id="opentask">$name</a>
</h5>
</div>
<div id="2" class="panel-collapse collapse">
<div class="panel-body">body text</div>
</div>
</div>
</div>
Then I have a static value like $loggeduser which is always the same for the logged user.
As this is a dynamically created accordion though, the id of each accordion section is different
What I am trying to achieve is when the user click to open the accordion, in the same time to execute an AJAX request which will send the value of the $loggeduser together with the id of the accordion in which the clicked link is placed in.
This is the ajax I am using to send the info to the file
$(function(){
$("#opentask").click(function(){
$.get("markread-task.php?id=ID&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
but I cant figure out how to to have a different ID in this link
markread-task.php?id=ID&user=LOGGEDUSERCOMMENT
for example if the user click on the link that opend accordion 2, the ajax sends link like
markread-task.php?id=2&user=LOGGEDUSERCOMMENT
Thanks for your help
javascript jquery ajax
javascript jquery ajax
asked Jan 3 at 13:40
lStoilovlStoilov
2551418
2551418
We would need more code in order to help you here, there could be many possible solutions depending on how it's implemented.
– Armel
Jan 3 at 13:44
what else do you need ?
– lStoilov
Jan 3 at 14:40
add a comment |
We would need more code in order to help you here, there could be many possible solutions depending on how it's implemented.
– Armel
Jan 3 at 13:44
what else do you need ?
– lStoilov
Jan 3 at 14:40
We would need more code in order to help you here, there could be many possible solutions depending on how it's implemented.
– Armel
Jan 3 at 13:44
We would need more code in order to help you here, there could be many possible solutions depending on how it's implemented.
– Armel
Jan 3 at 13:44
what else do you need ?
– lStoilov
Jan 3 at 14:40
what else do you need ?
– lStoilov
Jan 3 at 14:40
add a comment |
1 Answer
1
active
oldest
votes
First of all, Id must be unique to each element. Use class or name instead. So you cannot have two elements with id="opentask".
To get data-id value in your click method:
$(function(){
$(".opentask").click(function(){
var id = $(this).data('id');
$.get("markread-task.php?id="+id+"&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
1
I would suggest that a pseudo class be used to get round the unique id. e.g.$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023453%2fsend-ajax-request-by-clicking-a-link-inside-a-dynamically-created-bootstrap-acco%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, Id must be unique to each element. Use class or name instead. So you cannot have two elements with id="opentask".
To get data-id value in your click method:
$(function(){
$(".opentask").click(function(){
var id = $(this).data('id');
$.get("markread-task.php?id="+id+"&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
1
I would suggest that a pseudo class be used to get round the unique id. e.g.$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
add a comment |
First of all, Id must be unique to each element. Use class or name instead. So you cannot have two elements with id="opentask".
To get data-id value in your click method:
$(function(){
$(".opentask").click(function(){
var id = $(this).data('id');
$.get("markread-task.php?id="+id+"&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
1
I would suggest that a pseudo class be used to get round the unique id. e.g.$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
add a comment |
First of all, Id must be unique to each element. Use class or name instead. So you cannot have two elements with id="opentask".
To get data-id value in your click method:
$(function(){
$(".opentask").click(function(){
var id = $(this).data('id');
$.get("markread-task.php?id="+id+"&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
First of all, Id must be unique to each element. Use class or name instead. So you cannot have two elements with id="opentask".
To get data-id value in your click method:
$(function(){
$(".opentask").click(function(){
var id = $(this).data('id');
$.get("markread-task.php?id="+id+"&user=LOGGEDUSERCOMMENT",function(data){
});
});
return false;
});
edited Jan 3 at 14:06
answered Jan 3 at 13:49
maximelian1986maximelian1986
907519
907519
1
I would suggest that a pseudo class be used to get round the unique id. e.g.$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
add a comment |
1
I would suggest that a pseudo class be used to get round the unique id. e.g.$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
1
1
I would suggest that a pseudo class be used to get round the unique id. e.g.
$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
I would suggest that a pseudo class be used to get round the unique id. e.g.
$(".tasktitle").click(function(){ ......
– Steve
Jan 3 at 14:04
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@maximelian1986, I have tried that,but it doesn't work
– lStoilov
Jan 3 at 14:51
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@Steve, I have tried that too, but still doesn't work
– lStoilov
Jan 3 at 14:52
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
@maximelian1986, It worked actually. I was passing the wrong id so, didn't work at that time.
– lStoilov
Jan 3 at 20:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023453%2fsend-ajax-request-by-clicking-a-link-inside-a-dynamically-created-bootstrap-acco%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
We would need more code in order to help you here, there could be many possible solutions depending on how it's implemented.
– Armel
Jan 3 at 13:44
what else do you need ?
– lStoilov
Jan 3 at 14:40