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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:43:06+00:00 2026-06-17T16:43:06+00:00

I got this code: function datatable_display(json) { var order = desc; var len =

  • 0

I got this code:

function datatable_display(json) {

    var order = "desc";

    var len = $('.div_gui_tabledata').length;
    len = len++;
    var table = $('#dynamic_' + len);

    document.write("<div class='div_gui_tabledata' id='dynamic_" + len + "' >");


    this.array = JSON.stringify(json);

    $.ajax({
        type: "POST",
        url: "../../api.php?p=datatable_sort",
        data: "sortby=2&data=" + array,
        dataType: "html",
        success: function (data) {
            $('#dynamic_' + len).html(data);
        }
    });

    document.write("</div>");


    $('#dynamic_' + len + ' .sortable').live("click", function () {

        var index = $(this).index();


        $.ajax({
            type: "POST",
            url: "../../api.php?p=datatable_sort",
            data: "order=" + order + "&sortby=" + index + "&data=" + array,
            dataType: "html",
            success: function (data) {
                $('#dynamic_' + len).html(data);
                if (order == "desc")
                    order = "asc";
                else
                    order = "desc";
            }
        });
    });

}

I call this function from my PHP-Script like that:

 $json = json_encode($this->arr);
 return "<script>datatable_display($json);</script></div>";

When I call the function twice or even more times, the problem is the json-Object Array is always overwritten by the last.

Is there something like OOP in Javascript? Or something that threatens each function call unique? I generate unique ids for the divs and the Sort-Links, but then only the latest JSON Object is used.

  • 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-17T16:43:07+00:00Added an answer on June 17, 2026 at 4:43 pm

    There are a variety of architectural things you could be doing differently to make life a lot easier for yourself, but you’re likely to discover these in time on your own. To answer your immediate question, using javascript’s built-in objects should solve your problem.

    var str = "something"; // choose your own key
    this.store = {}
    this.store[str] = JSON.stringify(json);
    

    or

    this.array = []; // in your initializer or constructor
    this.array.push(JSON.stringify(json)); // this will add to the array as you go
    

    In this way you can keep a history of json without overwriting what you had before.

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

Sidebar

Related Questions

I've got this code... function disableSheets(){ console.log(document.styleSheets.length); var c = document.styleSheets.length; for(var i=0;i<c;i++){ console.log(document.styleSheets[i]);
I got this code: function zeroPad(num, places) { var zero = places - num.toString().length
So i got this snippet of code: $(document).ready(function () { var replacementDoneIn = $(body).html();
I have got code like this var challegneListener; $(document).ready(function(){ var challegneListener = setInterval(challengeListenerBot(),5000); });
I've got this code - $(document).ready(function() { $(function(){ $(#result).submit(function(e) { e.preventDefault(); var ele =
I've got this code in jQuery: $(document).ready(function() { // sprawdzanie wartości url var hash
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
In order to highlight spacing between Chinese characters I've got this code function replaceSpaces(){
I've got this code throwing an error from an iframe: function parentIframeResize() { var
I've got this code and I don't know how to order my query function

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.