2

We are using three divs in our application.

  1. Header

  2. Middle portion

  3. Footer

    Url of the application : http://localhost:8080/APPNAME/index.jsp

Header contains three buttons. If we click on the buttons we will change the middle portion div content using the following code:

$('div#middleportion').load('login.jsp');
$('div#middleportion').load('register.jsp');
$('div#middleportion').load('home.jsp');   

Successfully we are loading content. My problem is if we click on login button we are able to display login content in middle portion div, but I need to change the URL as follows:

http://localhost:8080/APPNAME/login.jsp

How to achieve this?

Please help me.Help would be appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Kiran
  • 20,167
  • 11
  • 67
  • 99
  • You application is hosted on your local machine, we will not able to see it. – kazinix Oct 28 '11 at 06:07
  • http://stackoverflow.com/questions/846954/change-url-and-redirect-in-jquery – sdolgy Oct 28 '11 at 06:07
  • @domanokz.. no for explanation i attached the address but i need to change the address using javascript how to achieve? – Kiran Oct 28 '11 at 06:08
  • @sdolgy.. The code you have refered is reloading the whole page but i need to change the url when the div content is changed? – Kiran Oct 28 '11 at 06:13

1 Answers1

1

jquery address plugin

EDIT:

I actually had to do the same thing that you're lookin for (from what i understand).

for pages that I wanted to be loaded dynamically (just the div) I created a version without the layout. for example, for login.jsp I had ajax/login.jsp (which had only the actual div).

since I normally work with mvc and layouts, it was easy to separate the div from the layout on the server side.

In the plugin I made sure that the url's that are being replaced are only the ones with the class ajax and I added this class to all of the links that i wanted to change the div only.

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
galchen
  • 5,252
  • 3
  • 29
  • 43
  • Thanks a lot for quick reply.. But this plugin is reloading the page content.i need to reload only div content and i need to change the url. – Kiran Oct 28 '11 at 06:28
  • Thank you very much but here in our application we are using any ajax call so that we need to load jsp pages from client side.The plugin will load from server side. – Kiran Oct 28 '11 at 06:58
  • you want a script that loads only the div from login.jsp from the client side? – galchen Oct 28 '11 at 11:48
  • Actually am able to load login.jsp in div but i need to change the url without reloading the page. – Kiran Oct 28 '11 at 11:52
  • ah then you can use window.history.pushState to store the history (use back/forward). window.history.pushState(data, "title", "/newpath"); – galchen Oct 28 '11 at 12:26
  • prior to HTML5 you would use window.location.hash to add #path to the url. now you can use the history object alone – galchen Oct 28 '11 at 12:29