-1

I want to load data from the database when i click on an a link. My links are data from a database. This is how I do it in my view:

<div id="wijken">
              <ul>
            <?php foreach($this->districts as $districts) : ?>
              <li><a><?php echo $this->escape($districts->wijk); ?></a></li>       
            <?php endforeach; ?>
              </ul>
          </div>

This is how it looks: enter image description here

Now I want that when you click on a link that I can load data and show data from the database depending on the link you clicked. How can I do this?

I tried it with javascript. Is it possible that you can load data with ajax call to an action in a controller?

My javascript:

$("#wijken ul li a").click(function(e){  

var wijk = ($(this).text());

$.ajax({ 

  type: "POST",
  url: "index/test",                    
  data: "wijk",                        

  dataType: 'json',                
  success: function(rows)          
  {
      alert("worked!");

  }, 
  error: function(error){
      alert("didn't worked!");
  }

  });

Could this work or not?

6
  • "Could this work or not?" So try and you will get answer... Commented Jan 22, 2013 at 17:23
  • I didn't work, i get always error. But maybe it's my testaction that doesn't work. I want to know if it's possible to do this before I check that. Commented Jan 22, 2013 at 17:24
  • alert("didn't worked!"); ... ajax call error Commented Jan 22, 2013 at 17:43
  • Check your php_error log what says? you can find path to error_log in phpinfo() or you can call your Ajax action to see error(maybe), just in browser type localhost/project/index/test/wijk and ypu will see json string or error Commented Jan 22, 2013 at 17:46
  • 1
    your data param in JS is wring... check this stackoverflow.com/a/8489447/949273 Commented Jan 22, 2013 at 17:51

1 Answer 1

2

This answer can help you

https://stackoverflow.com/a/8489447/949273

It is a simple example of using Zend Framework and Ajax(JQuery).

Sign up to request clarification or add additional context in comments.

1 Comment

Please do not vote up this answer. Vote up real answer on link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.