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!
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>
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;
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.