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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:05:03+00:00 2026-05-27T22:05:03+00:00

I have code which posts a variable to php: $(document).ready(function() { $(‘ul.sub_menu a’).click(function() {

  • 0

I have code which posts a variable to php:

$(document).ready(function() {
    $('ul.sub_menu a').click(function() {
        var txt = $(this).text();  
        //console.log("you clicked"+txt);
            $.ajax({
        type: 'POST',
        url: 'thegamer.php',
        data: {send_txt: txt},
        success: function( data ){
        //now echo the data where you want
        // for example
        //$('#result').html( data );
        // or you can see in on firebug
        console.log( 'Return:' + data );
            }               
     });
});
});

The php that gets the request:

   <?php
include 'dbconnect.php';
$q=$_REQUEST['send_txt'];

  //echo $q;

 $sql="select imgurl from images where family='shoes'";
$result = mysql_query($sql);


include 'dbclose.php';
?>

How do I return the data back to the ajax request?

  • 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-27T22:05:04+00:00Added an answer on May 27, 2026 at 10:05 pm

    Hm, I really suggest you learn more about Javascript, JQuery, AJAX and PHP before you attempt it. It looks like you have no clue how to go about this.

    I’ll point you in the right direction starting with W3 Schools (although definitely not the best resource but, it’s a good start):

    W3 Schools

    • Javascript
    • JQuery
    • PHP

    Here’s some more information about JQuery from their own JQuery API Documentation

    More specifically, the $.ajax function

    And here’s how you connect to a Mysql database using PHP


    With that being said, this is a general example, using your information, of how you would go about doing an AJAX/server response. I post this so that you might learn something from this code, as it does specifically what you requested:

    Javascript

    $(document).ready(function() {
        $('#element').click(function() {
            //Get data to be sent to server
            //var sFamily = $("#family_search").text();
            //var sFamily = $(this).text();
            var sFamily = "family";
            $.ajax({
                type: 'POST',
                url: 'thegamer.php',
                data: {family: sFamily },
                success: function(response){
                    //Use response
                    //alert("Server echo: "+response);
                    $("#output_element").html(response);
                },
                error: function(msg){
                    alert("Error: "+msg);
                }
            });
        });
    });
    

    PHP file “thegamer.php”

    <?php
        //Credentials
        $server = "localhost";
        $user = "root";
        $password ="admin";
        $db = "dbo";
    
        //Connect
        $link = mysql_connect($server, $user, $password);
        //Select database
        mysql_select_db($db, $link);
    
        //Assemble query
        $family = mysql_real_escape_string($_POST['family'], $link);
        $query = "SELECT imgurl FROM images WHERE family='$family'";
    
        //Query database
        $result = mysql_query($query, $link);
    
        //Output result, send back to ajax as var 'response'
        echo "<table>";
        if(mysql_num_rows($result) > 0){
            //Fetch rows
            while($row = mysql_fetch_array($result)){
                echo "<tr><td>".$row['imgurl']."</td></tr>";
            }
        }else{
            echo "<tr><td>No results matching family \"$family\"</td></tr>";
        }
        echo "</table>";
    
        //mysql_free_result($result)
        //mysql_close($link);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which gets WP posts, but it gets all the posts
I have a stupid question :) I'm working on a simple php document which
I have the following jQuery code to execute when I click a button $('#substat').click(function()
I have this ajax jquery code: var form = document.getElementById('frm'); var data_string = form.serialize();
I have the following line of PHP code which works great: exec( 'wget http://www.mydomain.com/u1.php
I have drawn up the following PHP code which processes the data from a
I have the following code which works just fine when the method is POST,
I have the following piece of code which replaces template markers such as %POST_TITLE%
I have code which needs to do something like this There is a list
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {

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.