Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:27:49+00:00 2026-05-16T15:27:49+00:00

I am using AJAX/JSON combination in Zend Framework. Whenever I click any link in

  • 0

I am using AJAX/JSON combination in Zend Framework. Whenever I click any link in my application, AJAX request is called and content is loaded successfully in DIVs But the address bar is unchanged. How to change address bar according to current active action.

Here is My Working Code:

When I use http://practice.dev/ my index.phtml file is loaded.

<a href='http://practice.dev/index/one' class='ajax'>One</a>
<a href='http://practice.dev/index/two' class='ajax'>Two</a>

<div id="content">content comes here</div>

one.phtml:

$jsonArray = array( 'content' => 'One' );
echo Zend_Json::encode( $jsonArray );

two.phtml:

$jsonArray = array( 'content' => 'Two' );
echo Zend_Json::encode( $jsonArray );

JS Code

jQuery(document).ready(function(){
    jQuery('.ajax').click(function(event) {
        event.preventDefault();
        jQuery.getJSON(this.href, function(snippets) {
            for(var id in snippets) {
                jQuery('#' + id).html(snippets[id]);
            }
        });
    });
});

When I click link one then string ‘One’ is loaded in content DIV but address bar is still http://practice.dev/. It should be http://practice.dev/index/one

When I click link two then string ‘Two’ is loaded in content DIV but address bar is still http://practice.dev/. It should be http://practice.dev/index/two

How is it possible ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:27:49+00:00Added an answer on May 16, 2026 at 3:27 pm

    Remove event.preventDefault();, this is stopping the default behavior for the link occurring. The default behavior being – going to the URL in the href attribute.

    Edit based on more info from OP

    You need to make your javascript respond to the hash tag.

    Instead of having a URL schema just like this http://practice.dev/index/one it needs to have a hash tag version too, that javascript can handle like this http://practice.dev/index#one. This means that if someone visits the page http://practice.dev/index#two your javascript can know that it needs to go and get the second page, even though Zend will have got the first page already.

    In your javascript you can get the hash tag using

    var hash = location.hash;
    

    And set it using

    location.hash = "two";
    

    There is more about this here

    So leave your links the same like this http://practice.dev/index/one but append a hash tag to the URL when the user clicks a link, you CAN add hash tags the address bar. Change your javascript to load a certain page number if there is a hash tag present when the page loads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
Anyone have any experience creating a modal dialog box using AJAX and ASP.NET MVC?
How do I preview a url using ajax? I have seen this done with
Can you do ajax on ASP.net webform without using ajax toolkit? (Please post a
I am creating a chat using Ajax requests and I'm trying to get messages
I'm using $.post() to call a servlet using Ajax and then using the resulting
I need to upload images using FileUpload without postback(using Ajax).I tried many examples.But in
Does anybody know of an up to date tutorial on using Ajax with ASP.net
Im trying to find a best practice to load usercontrols using Ajax. My first
I have some forms that communicate with server using AJAX for real reasons: cascade

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.