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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:54:12+00:00 2026-06-13T23:54:12+00:00

I have a PHP page that uses a jQuery ajax call. After I execute

  • 0

I have a PHP page that uses a jQuery ajax call.

After I execute my AJAX and return a value on success, I need to use this value to pull an item from a PHP array, stored in session and update my SPAN with the new set.

Here’s what I’ve got so far. I tested and I do return correct data value. I guess my syntax in jQuery is off, because my original span fades out, but nothing comes back.

JS:

$.ajax({ 
    ...
},
success: function(data){
    var nextItem = <?php echo $_SESSION['items'][data]->desc; ?>
    $('.x').fadeOut();
    $('.x').attr(id, data); 
    $('.x').text(nextItem).fadeIn();    
}); 

HTML:

<span id="'.$_SESSION['items'][0]->id.'" class="x">'.$_SESSION['items'][0]->desc.'</span>
  • 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-13T23:54:14+00:00Added an answer on June 13, 2026 at 11:54 pm

    You should return the session variable in the AJAX call. Execute the PHP code to get the session variable on the URL your AJAX call is hitting. The response of the AJAX call (in this case the ‘data’ variable in your success function) will be the result of:

    <?php echo $_SESSION['items'][data]->desc; ?> 
    

    So no PHP code will be in your JS.

    If you need to return multiple values, then you might consider using JSON. Your AJAX processing page might be like:

    $result = array('id' => $id, 'session' => $_SESSION['items'][$id]->desc);
    echo json_encode($result);
    

    Your JS might look like this:

    $("#getJSON").click(function() {
        $.ajax({
            ...
            success: function(data) {
                $obj = $.parseJSON(data);
                console.log($obj[0].id, $obj[0].session);
            }
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JQUERY function that uses AJAX via a PHP page, when the
I have a page index.php that uses a modal to upload files. After those
I am new to jQuery / AJAX. I have a page that uses colorbox
I have a website that uses ajax jquery and facebox. Demo here : http://temp.nevergone.eu/facebox.php
I have simple AJAX function that uses jQuery to return an array of 300
I have a php page that uses php sessions as well as jquery to
I have a dialog window that uses a URL for its contents { function(){jQuery.ajax({'success':function(html)
I have a div in my php page that uses jQuery to hide it
I have a sample page that uses 2 PHP files and a MySql database,
I have a PHP script that uses CURL to fetch a remote page and

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.