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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:12:29+00:00 2026-05-23T04:12:29+00:00

EDIT : Check at the end of this for the solution I am new

  • 0

EDIT: Check at the end of this for the solution

I am new to php, ajax and all other things 🙂

My question is: is there a way for a php file to return a value?

I have:

  1. a file “loadImages.php” containing the script to get the paths to images from the database.
  2. an image gallery where I want to load images via ajax.
  3. a database containing the path to the images (/images/image1.jpg, /images/image2.jpg).
  4. 4 categories of images.

What i’m trying to do is :

When clicking on a link (example, first category), I want to call via jquery’s ajax(), loadImages.php with the category passed via POST (cat0, cat1, cat2, …)

I want to return the value from this php file for example : <img src="image/image1.jpg" />, so via javascript, I can retrieve this string. Using only return in my php file returns XMLHttpRequest when i’m putting the ajax() function in a variable instead of the string <img>.

Is there a way to do it? Or maybe a better way, as I don’t fully understand ajax.

Thank you! Sorry for my bad grammar.

Below is a more precise map of what i’m trying to do.

JavaScript:

var test = $.ajax({  
type: "POST",  
    url: "loadImages12.php",  
    data: "category=0",  
    complete: function() {  
        alert("COMPLETE");  
    },  
    error: function (){  
        alert("NOT LOADED");  
    }  
});

PHP (loadImages.php)

function createThumb() { 
        if(isset($_POST['category'])) {  
            $imageQuery = mysql_query("SELECT * FROM t_pictures WHERE p_category = 0");
            $thumbHtml = '';

            while ($tempImageQueryFetch = mysql_fetch_assoc($imageQuery)){
                $thumbHtml .= '<a href="#" class="thumbnail"><img src="ressources/images/' . $tempImageQueryFetch["p_fileName"] . 'Small.jpg" /></a>';
            }

        return $thumbHtml;
        }
        else {
            $noCategory = "NO CATEGORY TEST";
            return $noCategory ;
        }
    }

    createThumb();

SOLVED

  • Php File

    function createThumb(){
    //Mysql request
    $someVar = //Result of request
    return $someVar
    }

    echo createThumb()

  • Javascript

    $(“#someDiv”).load(“loadImages.php”, {category:0});

  • 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-23T04:12:29+00:00Added an answer on May 23, 2026 at 4:12 am

    An AJAX request to PHP is exactly the same as a normal request for a website. You request data from example.com/foo/bar and in return you receive text. The return statement of PHP has nothing to do with what’s returned to the client. Only things you echo or otherwise output will be received by the client. That’s the same for normal pages and AJAX requests.

    So, to “return” <img src="image/image1.jpg" /> to your Javascript AJAX call, echo that string in PHP.

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

Sidebar

Related Questions

EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit 3: For the code itself all together check the first answer or the
Edit: I'm trying to check the user input against a array of allowed inputs
Edit: For a detailed how-to, check out my answer . I'm struggling with it
----EDIT---- I am making an jquery mobile application. Now I want to check which
I'm coding an edit form and I can't get the part where you check
i use netbeans to check out projects from svn repo, then i edit the
Edit (updated question) I have a simple C program: // it is not important
Edit: solution added. Hi, I currently have some working albeit slow code. It merges
EDIT After staring at this for 2 days, I do see one issue. I

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.