AJAX reload div (not from separate file)

Javascript coding ..

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 50
Joined: Fri Jan 20, 2012 8:00 am

AJAX reload div (not from separate file)

Postby iam4423 » Wed Jul 25, 2012 10:19 am

Okay so im not too sure if this is possible, for that matter i dont think it will be possible but i though i might as well ask before i work round it.

Here is an example of the kind of thing im looking at

Code: Select all

<?php require("comments_lib.php");
$comment_class= new Comments('Some','Data','Passed')?>

<div id="post">
<p>This is a random post</p>

<div id="comments"><?php $comment_class->display_comments();?></div>

So that is a very simplified version of a page that i am trying to make and basically i want to use AJAX to reload the div #comments without having to reload the full page... is this possible and if so how?

if i can get away with it i dont really want to use JQuery but i will if i have to.

Any help would be appreciated.


New php-forum User
New php-forum User
Posts: 109
Joined: Thu May 03, 2012 7:22 am

Re: AJAX reload div (not from separate file)

Postby faust » Wed Aug 01, 2012 2:28 am

You don't HAVE to use jquery, but I recommend it. It's easy, clean and reliable. At least, I have no problems with it for now. Here's something you can try:
1. Add a link to your page. Something like this:

Code: Select all

<a href="#" onclick="load_ajax_content();">Load Ajax</a>

2. Make a new js file with this function and include it in your page:

Code: Select all

function load_ajax_content()
  url: 'get_content.php', //here comes your url to the php script that returns the info that you want
  success: function(response) {
    alert('Load was performed.'); //you don't need the alert but it's good for testing

Try this and tell how it went :)

Return to “JavaScript”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest