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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:29:17+00:00 2026-05-24T00:29:17+00:00

I have some ajax code that executes on mouseclick. It calls a file called

  • 0

I have some ajax code that executes on mouseclick. It calls a file called update.php that does a bunch of stuff, including checking for user permissions, numerous database calls, etc. In the end, I also want to be able to return a few variables from PHP for the callback to use, but not sure how to reference them – or if there’s a better way to return this info.

$.ajax({
type: "POST",
url: "update.php",
data: dataString,
success: callback 

});

function callback(data, status)
{
// $("div").text(data);
$("div.numbert").text("[first variable here]");
$("div.numbert2").text("[second variable here]");
        }

From my update.php file (some snippets):

    if ($check_access > 0)
    {
// Update database 

$sql = "UPDATE db SET access = '1' WHERE user = '$user'";
$result = mysql_query($sql) or die(mysql_error());


// Give access - function returns data to variable
$value = GiveAccess($user);


// Email - function returns data to variable
$emaillist = emailAdmins($user);    

    } else {

$message = "Sorry you do not have access";
    }

So I’d like to figure out how to use the variables $message, $value and $emaillist in my callback if possible.

I’m wondering if I just need to make multiple $.ajax POST calls, with each .php function that returns a variable having it’s own call?

Thanks!


—-UPDATE——-

Updated code trying to use the json methods – thanks for all the help – but seems I’m missing one last thing.

    $.ajax({
type: "POST",
url: "update.php",
data: dataString,
dataType: 'json',
    success: callback 

});

function callback(data, status)
{
// $("div").text(data);
$("div.numbert").text(data.value);
$("div.numbert2").text(data.emaillist);

and update.php:

    $storage = array();
// Update database 

$sql = "UPDATE db SET access = '1' WHERE user = '$user'";
$result = mysql_query($sql) or die(mysql_error());


// Give access - function returns data to variable
$storage['value'] = "some user";


// Email - function returns data to variable
    $storage['emaillist'] = "some stuff";   

    header('Content-type: application/json');
    echo json_encode($storage);
    exit(0);    

Thanks again.

  • 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-24T00:29:18+00:00Added an answer on May 24, 2026 at 12:29 am

    You can use a JSON wrapper:

    $messages = array();
    $messages['value'] = GiveAccess($user);
    $messages['emaillist'] = emailAdmins($user);
    $messages['message'] = "Sorry you do not have access";
    
    echo json_encode($messages);
    

    And then simply use:

    data.value    data.emaillist    data.message 
    

    in your Javascript.

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

Sidebar

Related Questions

I have some jQuery code. I have called an Ajax function file, file.php, that
I have some AJAX work that brings across an additional form element that I
I have some forms that communicate with server using AJAX for real reasons: cascade
I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I have some content from server using $.ajax() function. I try to replace some
I have coded some JavaScript to perform an ajax call in an asp.net application.
I have an application in which most requests are submitted via AJAX, though some
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.

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.