I have an input that the user can type something and an ajax request fetch these results in the database via php, works fine, then each result, when clicked, has a more detailed page about it, that works fine too, except that i would like it to have a unique url that i can link to someone instead of being the same. For instance: i want this 'www.mysite.com/allItems.php?=detailedItem' and at the moment it's just www.mysite.com/allItems.php even when i'm in detailed page. I already tried with 'a' tag but didn't work.
var handleSearch = function(id, isStateBack) {
var popID = typeof id != 'undefined' ? id : $(this).attr('id');
if (!isStateBack) {
window.history.pushState({popID: popID}, 'Search: ' + popID, 'work.php?=' + encodeURIComponent(popID));
}
$.get('AjaxSpecifics.php', {"details": popID}, function(data) {
$('html').stop().html(data).hide().fadeIn(500);
});
return false;
};
$(document).on('click', '.imageSearchAjax', handleSearch);
// popstate event
window.addEventListener("popstate", function() {
var currentState = history.state;
if (typeof currentState.popID != 'undefined') {
// this state has 'popID' property, handle it
handleSearch(currentState.popID, true);
}
});