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 937239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:26:41+00:00 2026-05-15T21:26:41+00:00

I am using zend framework on windows. I want to implement ajax in my

  • 0

I am using zend framework on windows. I want to implement ajax in my project first time. I searched for help and created a very simple ajax functionality.

IndexController.php

public function indexAction() {
}

public function oneAction() {
}

public function twoAction() {
}

index.phtml

<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="js/AJAX.js"></script>

<a href='http://practice.dev/index/one' class='one'>One</a>
<a href='http://practice.dev/index/two' class='two'>Two</a>
<br /><br />
<div id="one">one.phtml content comes here</div>
<div id="two">two.phtml content comes here</div>

AJAX.js

jQuery(document).ready(function(){
    jQuery('.one').click(loadOne);
    jQuery('.two').click(loadTwo);
});

function loadOne(event) {

    event.preventDefault();

    jQuery.ajax({
        url: '/index/one',
        success: function( data ) {
                    jQuery('#one').html(data);
                    }
    });
}

function loadTwo(event) {

    event.preventDefault();

    jQuery.ajax({
        url: '/index/two',
        success: function( data ){
                    jQuery('#two').html(data);
                    }
    });
}

Above code is working and loading data of one.phtml and two.phtml in ‘one’ and ‘two’ DIVs respectively when its link is clicked. You can see that I have to create separate jquery function for each link and also have to add new class for each link tag.

What I want to do ?:

I want to use only one jquery function for all AJAX requests and don’t want to hard code url and success attributes in that function.

When I add “AJAX” class to any link tag then it should load content using AJAX.

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-15T21:26:42+00:00Added an answer on May 15, 2026 at 9:26 pm

    for simple loading of data in divs i would use the load method

    HTML

    <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="js/AJAX.js"></script>
    
    <a href='http://practice.dev/index/one' class='ajax' rel="one">One</a>
    <a href='http://practice.dev/index/two' class='ajax' rel="two">Two</a>
    <br /><br />
    <div id="one">one.phtml content comes here</div>
    <div id="two">two.phtml content comes here</div>
    

    JS

    jQuery(document).ready(function(){
        jQuery('.ajax').click(function(event){
           event.preventDefault();
    
           var target = '#' + jQuery(this).attr('rel');
           var href = jQuery(this).attr('href');
           jQuery( target ).load( href );
    
          });
    });
    

    Use a single class to identify all links that should use ajax calls instead of their normal use. And add a rel attribute to those links that will contain the id of the container div..

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

Sidebar

Related Questions

I am developing a project on windows with wamp installed using zend framework. Unfortunately
This is my first experience using the Zend Framework. I am attempting to follow
I started working on a project in the mid. We are using Zend Framework,
I'm using some Zend libraries outside of the Zend Framework in a small project.
I am using Zend Framework(MVC part of it), and need to either redirect user
I am using the Zend Framework. I have a controller named 'UserController' that has
I have been using the Zend Framework with an MVC configuration, read about Ruby
I am trying to implement a Flash uploader in my Zend framework application but
I'm using the zend community server on windows vista. I'm following the tutorial in
I am using Zend Framework 1.6 hence I'm not utilizing Zend_Application. I have a

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.