Geeth Welagedara Geeth Welagedara - 4 months ago 48
Ajax Question

How to make Code Igniter ajax request URL appear to browser URL.

I'm using

code-igniter
framework
. When i click or select following
panel1
any option, each click and select event i made as to call Ajax function and user information will appear to
panel2
DIV
tag.
I can't see full URL on my address bar. How to display the ajax request URL on the browser address bar.

enter image description here

var ajaxUrl = '<?php echo base_url(); ?>' + 'main/userinfo/' + gender + '/' + age_min + '/' + age_max;
$.ajax({
url: ajaxUrl,
dataType: "JSON",
type: "POST",
success: function(retdata) {


});

Answer

There are loads of articles, even here in SO, that explain how to change the url of the adress bar wihtout refreshing the page( while performing an ajax call for instance). The base idea is to use HTML5 History API (the pushState()). Something like:

var ajaxUrl = '<?php echo base_url(); ?>' + 'main/userinfo/' + gender + '/' + age_min + '/' + age_max;
$.ajax({
  url: ajaxUrl,
  dataType: "JSON",
  type: "POST",
  success: function(retdata) {

   window.history.pushState({"html":retdata.html,"pageTitle":retdata.pageTitle},"", ajaxUrl);
  });

There is also a polyfill for this libaray called history.js for old browsers.