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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:21:59+00:00 2026-05-24T16:21:59+00:00

I have a comments board on my page, to which I load different topics

  • 0

I have a comments board on my page, to which I load different topics according to the page the user is on with XMLHttpRequest in a changeTopic() function. I originally had this at the end of my submit form php:

header('Location: http://' . $_SERVER['HTTP_HOST'] . $_POST['page']);

The problem is that I don’t want to refresh the whole page, only the DIV that contains the messages. I tried running the changeTopic() function by inserting it inside script tags with echo. For one, I couldn’t get .$_GET[‘topic’]. working inside echo even if I made a variable of it first, but also I tried running the function by hard inserting one of the possible values with the following results:

1) While the messages section refreshed right, I lost the form as it’s contained in the index.html while I only load the messages from an external gettopic.php with query string.

2) I got a weird result where I lost an external file that was loaded into a completely different div altogether. This file changes the hash of the main page, which is checked with every refresh and the right file is loaded according the hash, so using the whole page refresh never resulted in this.

// EDIT

function changeTopic(topic) {
        if (topic=="") {
            document.getElementById("messagelist").innerHTML="";
            return;
        }
        if (window.XMLHttpRequest) {
            xmlhttp=new XMLHttpRequest();
        }
        else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                document.getElementById("messagelist").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("POST", "gettopic.php?t="+topic,true);
        xmlhttp.send();
    }

The main application on my page is a SVG map which I’ve done with RaphaelJS. The user can load information pages into another div ‘info’ from this SVG map. The pages are loaded with a similar function which in addition changes the #hash and runs the changeTopic() as well to change the message board so people can have a conversation about each topic.

The PHP form takes the normal filled info as well as the hidden ‘pageid’ which is set by the current page the user is browsing, and sends it to the database. The different messages are sorted by this pageid so the changeTopic() function only brings the right messages: gettopic.php?t=topic (‘pageid’).

After submitting the form I’d like only the messagespart to refresh and the form to clear. At the moment it’s either a whole page refresh (user looses their position on the SVG map) or partial refresh where I lose the form (get a blank spot instead) and that weird information-page missing.

  • 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-24T16:22:01+00:00Added an answer on May 24, 2026 at 4:22 pm

    you can do something like this:

    var ajaxfoo = function(obj) {
        var xmlHttp = null;
        try {
            xmlHttp = new XMLHttpRequest();
        }catch(e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e) {
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }catch(e) {
                    xmlHttp = null;
                }
            }
        }if (xmlHttp) {
            obj.method = obj.method.toUpperCase();
            xmlHttp.open(obj.method, obj.url, true);
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            if(obj.method == 'POST') {
                if(typeof(obj.params) != 'undefined') {
                    xmlHttp.setRequestHeader("Content-length", obj.params.length);
                }
            }
            xmlHttp.setRequestHeader("Connection", "close");
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    var json = eval(xmlHttp.responseText);
                    if(json.success) {
                        if(typeof(obj.success) == 'function'){obj.success(xmlHttp.responseText);}
                    }
                    else {
                        if(typeof(obj.failure) == 'function') {obj.failure(xmlHttp.responseText);}
                    }
                }
            };
            if(obj.method == 'POST' && typeof(obj.params) != 'undefined') {
                xmlHttp.send(obj.params);
            }
            else {
                xmlHttp.send(null);
            }
        }
    };
    
    function callfoo(topicname) {
        ajaxfoo({
            method: 'GET',
            url: 'gettopic.php?t='+topicname,
            success: function(response) {
                var json = eval(response);
                alert('success callback function! '+json.data);
            },
            failure: function(response) {
                var json = eval(response);
                alert('failure callback function! '+json.data);
            }
        });
    }
    

    and in

    success: function(response) {
                var json = eval(response);
                alert('success callback function! '+json.data);
            },
    

    you can add your innerHTML stuff 🙂

    the gettopic.php

    should then echo something like:

    {success: true, data: [{id: 1, "title": "test title", "description": "moo"},{id: 2, "title": "test title", "description": "moo"},{id: 3, "title": "test title", "description": "moo"}]}
    

    And the you can access this by calling

    json.data[0].title
    json.data[1].title
    json.data[2].title
    json.data[0].description
    ...
    

    so you can simply build your innerHTML stuff by doing something like

    doc....innerHTML = '<h2>'+json.data[0].title+'</h2>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My scenario is that there are several different models which can have comments. Trying
What language(s) have comments with side effects? In essence, comments which are not comments....
I have a discussion board, and users can post comments on the board. But
I've worked with several different types of user-generated content sites: wikis, a message board,
So far i have @comments.count which gives me the number of all comments in
I have @comments which is either 0 -XXXX number of comments from the DB.
I have comments enabled on different types of pages in Wordpress (archive, tag, search,
i have comments function,i have status field in comments table ..i want to check
I'd like to have comments in my code, but I want them to be
I have some source files that have comments written in Japanese. When I open

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.