Saturday, 1 February 2014

How can I make a redirect page in jQuery/JavaScript?


It would help if you were a little more descriptive in what you are trying to do. If you are trying to generate paged data, there are some options in how you do this. You can generate separate links for each page that you want to be able to get directly to.
<a href='/path-to-page?page=1' class='pager-link'>1</a>
<a href='/path-to-page?page=2' class='pager-link'>2</a>
<span class='pager-link current-page'>3</a>
...
Note that the current page in the example is handled differently in the code and with CSS.
If you want the paged data to be changed via AJAX, this is where jQuery would come in. What you would do is add a click handler to each of the anchor tags corresponding to a different page. This click handler would invoke some jQuery code that goes and fetches the next page via AJAX and updates the table with the new data. The example below assumes that you have a web service that returns the new page data.
$(document).ready( function() {
$
('a.pager-link').click( function() {
var page = $(this).attr('href').split(/\?/)[1];
$
.ajax({
type
: 'POST',
url
: '/path-to-service',
data
: page,
success
: function(content) {
$
('#myTable').html(content); // replace
}
});
return false; // to stop link
});
});

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More