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

  • Home
  • SEARCH
  • 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 7090485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:03:37+00:00 2026-05-28T08:03:37+00:00

I have been looking around the internet for examples of an AJAX function which

  • 0

I have been looking around the internet for examples of an AJAX function which gets the latest messages from a database, I have been playing around with the code but I am stuck, currently I don’t know how I get the data from the php file to a variable in JQuery. sounds confusing maybe looking at my code will help.

any help is much appreciated.

JQuery code

$.ajax({
    type: "GET", url: "include/process.php", 
    data:{
       getLatestActivity: "true",
       toUser: "4"
    },
    success: function(data){
       alert("data: "+data);                   
    }
}); 

php processing request

function getLatestActivity(){
   global $session;

   $data = $session->getLatestActivity(mysql_real_escape_string($_REQUEST['toUser']));

   if($data){//successful
      return $data;
   }
}

The data function only prints out “data:”, Thanks in advance

  • 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-28T08:03:38+00:00Added an answer on May 28, 2026 at 8:03 am

    In order to pass data from PHP to Javascript you need to echo a string/json representation of what ever data you are trying to return. Note: echo json_encode($data);

    function getLatestActivity(){
       global $session;
    
       $data = $session->getLatestActivity(mysql_real_escape_string($_REQUEST['toUser']));
    
       if($data){//successful
          echo json_encode($data);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What exactly is StringIO used for? I have been looking around the internet for
I have been looking around the internet for a way to display specific content
I have been looking around for some way to convert a function or class
I have been looking around for examples related to converting JSON strings to Java
I have been looking for a way to do this all around the internet
I have been looking around the Internet but I am not sure if there
I have been looking all around the internet for the last couple of hours
I've been looking around the internet and haven't found out how, but have found
I have been looking around for solutions, and tried to implement what is often
I have been looking around ocn Google and Stackoverflow but haven't found what 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.