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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:38:31+00:00 2026-05-24T19:38:31+00:00

I have an ajax function outputs results of +1 and -1, in javascript, I

  • 0

I have an ajax function outputs results of +1 and -1, in javascript, I want to get the +1 response to use in colorbox.
This is the ajax function:

function my_ajax_obj_lightbox() {
    global $post;

    if ( !empty( $_POST['obj_id'] ) ) {

        $obj = new My_Obj( $_POST['obj_id'] );

        if ( $obj instanceof My_Obj ) {
            my_objs_ajax_response_string( 1, $obj->html() );
        }
    }

    my_objs_ajax_response_string( -1,  'Invalid request' );
}
add_filter( 'wp_ajax_obj_lightbox', 'my_ajax_obj_lightbox' );

Now , in javascript, I want to say something like this:

var response = ......; 
    if ( response[0] >= 1 ) {
            j.fn.colorbox({
            html: response[1],
            maxWidth: '90%',
            maxHeight: '90%'
            });
            }

How to define the var response and get ajax response as value ?

  • 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-24T19:38:32+00:00Added an answer on May 24, 2026 at 7:38 pm

    It sounds like you just need help setting up the AJAX request, and parsing the response into a JavaScript object…

    Let’s say you have a PHP file that returns a response in JSON format:

    <?php
        header('Content-type: application/json');
    ?>
    [1, "<h2><?php echo $_POST['title'] ?></h2>"]
    

    To retrieve this using AJAX, you can do something like this:

    <script>
    
      // Create the AJAX request object.
      var request = new XMLHttpRequest();
    
      // Define a function to handle the response.
      request.onreadystatechange = function() {
    
        // If the response is ready
        if (request.readyState == 4 && 
          request.status == 200) {
    
          // Transform the response into a JavaScript object.
          var response = eval(request.responseText);
          /*
          "response" is now a JavaScript array containing two values.
          */
    
          console.log(response[0]);
          /*
          1
          */
    
          console.log(response[1]);
          /*
          <h2>Hello World</h2>
          */
    
          // Write the contents of the response to an element on the page.
          if (response[0] >= 1) {
            var div = document.createElement("div");
            div.innerHTML = response[1];
            document.body.appendChild(div);
          }
        }
      };
    
      // Define some variables that we want to send to the server.
      var params = "foo=bar&baz=qux&title=" + encodeURIComponent("Hello World");
    
      // Post the data, and load the response asynchronously.
      request.open("POST", "/ajax-response.php", true);
      request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      request.send(params);
    </script>
    

    If you’re using jQuery, here’s the equivalent code:

    <script>
      $.post("/ajax-response.php", {
          foo: "bar",
          baz: "qux",
          title: "Hello World"
        },
        function(response) {
          if (response[0] >= 1) {
            $("body").append(response[1]);
          }
        }
      );
    </script>
    

    Documentation for jQuery post:
    http://api.jquery.com/jQuery.post/

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

Sidebar

Related Questions

I am using the jQuery $.ajax() function. I have put this into a parent
I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
I have a ajax function as below <script type=text/javascript> $(document).ready(function () { var timer,
I have the following javascript code: $.get(categories/json_get_cities/ + stateId, function(result) { //code here },
I have a jquery-ajax function that sends data to a php script and the
I have some jQuery code. I have called an Ajax function file, file.php, that
The problem seems very strange. I have a AJAX helper function within a same
The problem is the following. We have lots of ajax call via $.ajax function.
I have some content from server using $.ajax() function. I try to replace some
I have written a simple jQuery.ajax function which loads a user control from the

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.