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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:32:43+00:00 2026-06-09T00:32:43+00:00

When clicked on, a link should run PHP code that pulls info from a

  • 0

When clicked on, a link should run PHP code that pulls info from a database on the same page.

I have achieved this using AJAX, a form and a button but really wish to use a link instead of button.

I have managed to get the link to work but the table from the database that the PHP script creates only flashes up for a second as the browser is refreshed.

How do I stop the refresh so the table is displayed?

I would be very grateful for any help.

My code is:

    <script language="javascript" type="text/javascript">

    function myFunction(){
    var ajaxRequest;  

try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            // Something went wrong
            alert("Your browser has Failed");
            return false;
        }
    }
}

ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
        var ajaxDisplay = document.getElementById('ajaxDiv1');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;
    }
}

    document.proffForm.submit();
ajaxRequest.open("GET", "proff/all_proff.php");
ajaxRequest.send(null); 


    }

    </script>

    <form name='proffForm' >
    <a href="#" onclick='myFunction()' >List All Professions</a>
    </form>

    <div id='ajaxDiv1'></div></p>

php

     <?php 
     include '../dbc.php';



     $allprof1 = mysql_query("SELECT *  
                    FROM users 
                    ORDER BY profession" );

    $qry_result = mysql_query($allprof1) or die(mysql_error());
    ?>
    <?php     
    $display_string = "<table border='1' cellpadding='5' width='100%'               bordercolor='000099'border='solid'>";
    $display_string .= "<tr align='left' bgcolor='009966'>";
    $display_string .= "<th><span class='titlehdr3'>Profession</span></th>";
    $display_string .= "<th><span class='titlehdr3'>Business Name</span></th>";
   $display_string .= "<th><span class='titlehdr3'>Profile</span></th>";
   $display_string .= "</tr>";


   while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td><span class='tabs'>$row[profession]</span></td>";
$display_string .= "<td><span class='tabs'>$row[full_name]</span></td>";
$display_string .= "<td><span class='tabs'>$row[url]</span></td>";
$display_string .= "</tr>";

   }

   $display_string .= "</table>";
   echo $display_string;

   ?> 
  • 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-06-09T00:32:45+00:00Added an answer on June 9, 2026 at 12:32 am

    I can see, you have added submit function on the form. In ajax request we don’t need any submit action, so remove the line

    document.proffForm.submit();
    

    from your code. It will work perfectly.

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

Sidebar

Related Questions

I have a link that, when clicked, should deliver an email by using an
I have some jQuery code that highlights a link when clicked, and changes the
i have html page with a link when user clicked that link a new
I have a page which when an a link is clicked (which must remain
I have a javascript function that is called when a link is clicked. However
I'm using this snippet of code to grab a url from a clicked link:
I have a view that list Parts in a htmltable format from a database
Suppose that I click on a facebook link -- once clicked, the URL is
I wrote a code to show a div element(shareform) when a link is clicked
I have a User control (because I use the same in other page, so

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.