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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:31:10+00:00 2026-06-05T09:31:10+00:00

I am getting an ajax response from a PHP. I want to decode the

  • 0

I am getting an ajax response from a PHP. I want to decode the response , and get the 3 URL’s

The code is HTML/JS

<script type="text/javascript">
 $(document).ready(function() {
$(".goButton").click(function() {
   var dir =  $(this).attr("id");

   var imId = $(".theImage").attr("id");
   $.ajax({
      url: "viewnew.php",
      data: {
         current_image: imId,
         direction    : dir
      },
      success: function(ret) {
          alert(ret);
         $(".theImage").attr("src", ret);


         if ('prev' == dir) {
            imId ++;
         } else {
            imId --;
         }
         $("#theImage").attr("id", imId);
      }
   });

});
});
</script>


<body>
<img id="416" class="theImage" src="" />
  <a href="#null" class="goButton" id="next">Next</a>
</body>

And the PHP file is

$query = 'SELECT * FROM picture ORDER BY RANDOM() LIMIT 2';
$result = mysql_query($query);
$rec = mysql_fetch_array( $result, MYSQL_ASSOC );

echo $rec['pic_location'];

I want to get the next 3 image also so that i can show that these 2 images will come up in full screen when the next button is clicked. One will Appear as a full size and other as a thumbnail. How do i decode the response from the Ajax ?

  • 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-05T09:31:11+00:00Added an answer on June 5, 2026 at 9:31 am
     $(document).ready(function() {
    $(".goButton").click(function() {
       var dir =  $(this).attr("id");
    
       var imId = $(".theImage").attr("id");
       $.ajax({
          url: "viewnew.php",
          data: {
             current_image: imId,
             direction    : dir
          },
          success: function(ret) {
              var arr = eval(ret);
             alert("first: " + arr[0] + ", second: " + arr[1]);
    
    
             if ('prev' == dir) {
                imId ++;
             } else {
                imId --;
             }
             $("#theImage").attr("id", imId);
          }
       });
    
    });
    });
    

    Not tested, but I think it should work. (This code assumes PHP returns the json_encode()‘ed array)

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

Sidebar

Related Questions

I am getting ajax response in array format from php url. How to extract
I'm having trouble getting a response from my php jquery / json / ajax.
I have a code like this <script type=text/javascript> function email(){ var myTextField = document.getElementById('email_hidden').value;
I have been trying to do something like below. JavaScript $.ajax({ url: 'login.php', type:
This is my ajax post <script language=JavaScript type=text/javascript> var num = 1; function ajax_post(){
I am using this code to get response back from server. But I want
I am not getting response while fetching result from my code using AJAX. while
This php code is called through ajax from javascript and should return a numeric
I'm trying to POST a http request using ajax, but getting a response from
I'm having trouble getting a response back from a Jquery ajax call... (It's a

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.