views:

25

answers:

1

Basically I have a page with a quote in it. Underneath the quote, I will have a link that will be clicked and the quote will be updated with an ajax call from the database to display the new content. I can do it with a regular php file, but I wanted to add some ajax into the mix so that the entire page isn't refreshed each time.

Can someone explain how to do this? I scoped out http://stackoverflow.com/questions/2593090/random-quote-generator-with-php-ajax-and-mysql but the code given was giving me issues.

A: 

It looks like you're confused by ajax in that article. Try using jQuery's ajax like so:

$.ajax({
   'type': 'POST'
   'url' : 'yourfile.php',
   'success': function(data){
      $('#yourquote').html(data);
   }
});

That is all there is to it, provided yourfile.php returns just a random string representing your quote. Also - 'yourquote' is the id of the div or whatever you used to store your quote in.

Tell me if this helps.

Slavic