Reputation: 115
I am trying to use jQuery. To update a specific TD with innerHTML I am trying to figure out, how I can catch the value of the parameter.
In this example i need to catch the user-id "1234" so i can update the TD with the ID "status1234".
I am not very familar with javascript, I hope someone can give me a hint.
$(function() {
$('.ajax-link').click(function() {
$.get($(this).attr('href'), function(msg) {
alert("Data Saved: " + msg);
$("#status" & user).html("some content");
});
return false;
});
});
// TD with Link:
<td id="status1234">
<a href="/ajax_test.cfm?user=1234" class="ajax-link">Do the Ajax</a>
</td>
Thanx!
Upvotes: 0
Views: 35
Reputation: 1137
You may do like this
$(function() {
$('.ajax-link').click(function() {
var user=$(this).data('user');
$.get("/"+$(this).data('url')+"/user="+user, function(msg) {
alert("Data Saved: " + msg);
$("#status" + user).html("some content");
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td id="status1234">
<a data-url="ajax_test.cfm" data-user="1234" class="ajax-link">Do the Ajax</a>
</td>
Upvotes: 1
Reputation: 4397
Do this..
$(function() {
$('.ajax-link').click( function() {
var userTd = $(this).parent().attr('id');
$.get( $(this).attr('href'), function(msg) {
alert( "Data Saved: " + msg );
$("#"+userTd ).html("some content");
});
return false;
});
});
Upvotes: 0