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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:07:43+00:00 2026-06-16T17:07:43+00:00

I have a fully working JS code below but it is sending POST request

  • 0

I have a fully working JS code below but it is sending POST request to the server for every click event. How is it possible to cache the AJAX post response below?
Ideally, the cache should be saved as JS variables. If it is already loaded and present in the cache, it will be displayed (without doing POST). If it’s not loaded yet, it will do a POST request and save in the cache and then display.

jQuery( document ).ready( function( $ ) {
var _doing_ajaxx = false;
$('.toolbar').remove();
$('#mydiv #frontend').click(function() {    
    if (_doing_ajaxx) {
        return false;
    }

    var title_shortcode = $(this).text();


    var insert_namex=  $(this).attr('class');


    var titlejsselector=title_shortcode.replace(/ /g,'');


    var buttonval=$('#'+titlejsselector+' input').val();

    if (buttonval=='Minimize')  {
    //stop ajax request if button is set

        $('#'+titlejsselector+' div').remove();
        $('#'+titlejsselector+' input').remove();

    } else {
    //initialize ajax variables

    var data = {
            action: 'test_ajax_response',
            test_ajax_response_nonce: the_ajax_script.test_ajax_response_nonce, 
            postID_from_ajax : the_ajax_script.postid_to_ajax,
            insert_name_ajax: insert_namex,
            title_ajax: title_shortcode
        };      
    //do an ajax request
    _doing_ajaxx = true;
    $.post(the_ajax_script.ajaxurl, data, function(response) {

        $(this).next().slideToggle();   
        $('#mydiv #'+titlejsselector).append(response+"<input type='hidden' id='minimizebutton' value='Minimize'>");
        SyntaxHighlighter.highlight();

        $('.toolbar').remove();
        _doing_ajaxx = false;
    });

    }
    //return false;
}); 


});

I tried adding this code using PHP and it does not work:

 <?php
 header("Cache-Control: private, max-age=$seconds");
 header("Expires: ".gmdate('r', time()+$seconds));
 ?>

If someone can provide some sample code to get started, I would gladly appreciate it. Thanks.

  • 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-16T17:07:44+00:00Added an answer on June 16, 2026 at 5:07 pm

    If you want to cache from within the JS (so if they reload the page, the cache will no longer be there), I’d create an object and store the results:

    var cacheObj = {};
    

    Then, when you’re about to send the request:

    if (cacheObj.postID_from_ajax){
    
        display(cacheObj.postID);
    
    }else{
    
        // Do your ajax call
        $.post(the_ajax_script.ajaxurl, data, function(response) {
    
            _doing_ajaxx = false;
            cacheObj.postID_from_ajax = response;
            display(response);
    
        });
    }
    
    function display(response){
    
        $('#mydiv #frontend').next().slideToggle();   
        $('#mydiv #'+titlejsselector).append(response+"<input type='hidden' id='minimizebutton' value='Minimize'>");
        SyntaxHighlighter.highlight();
    
        $('.toolbar').remove();
    
    }
    

    Untested, but you should get the idea 🙂

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

Sidebar

Related Questions

I have a working php/mysqli code below where it inserts questions and answers successfully:
The code below was fully working when it was placed inside <script></script> tags on
OK, several questions about the test code below... I don't have the full working
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code
I'm working on some code which fills a GridView full of images that have
I have a fully working Setup project within Visual Studio 2008 that takes inputs
Ok, I have page one(index), fully functional and working fine as is with all
I am working on the Full Text Search in Sql Server 2005. I have
UPDATE: I have posted and accepted a fully working solution in the answers section.
I have done a global mouse event in my windows application. When i click

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.