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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:33:44+00:00 2026-05-15T11:33:44+00:00

I have made an Ajax request to a PHP script and that PHP script

  • 0

I have made an Ajax request to a PHP script and that PHP script returned this JSON object and when i tested with link text it says it’s valid

[
  {
    "id_annotation": "1",
    "annot_doc_id": "page_de_test.html",
    "annot_id_auteur": "2",
    "anno_startOffset": "47",
    "annot_startContainer": "id-aaa",
    "annot_endOffset": "88",
    "annot_forme": "1",
    "annot_value": "dispositif physique fait pour \n  stocker ",
    "annot_obj": "1",
    "annot_area": "",
    "annot_date": "vendredi 25 juin 2010 10:38:07"
  },
  {
    "id_annotation": "2",
    "annot_doc_id": "page_de_test.html",
    "annot_id_auteur": "2",
    "anno_startOffset": "122",
    "annot_startContainer": "id-aaa",
    "annot_endOffset": "200",
    "annot_forme": "1",
    "annot_value": " le plus simple est \n  d\u2019utiliser un syst\u00e8me de repr\u00e9sentation \u00e0 deux chiffres",
    "annot_obj": "1",
    "annot_area": "",
    "annot_date": "vendredi 25 juin 2010 10:38:19"
  },
  {
    "id_annotation": "3",
    "annot_doc_id": "page_de_test.html",
    "annot_id_auteur": "2",
    "anno_startOffset": "1",
    "annot_startContainer": "ident-77",
    "annot_endOffset": "146",
    "annot_forme": "1",
    "annot_value": "Dans un ordinateur, le dispositif qui permet de stocker de l\u2019information est donc \n  rudimentaire, bien plus rudimentaire que les mains humaines.",
    "annot_obj": "1",
    "annot_area": "",
    "annot_date": "vendredi 25 juin 2010 10:38:25"
  },
  {
    "id_annotation": "4",
    "annot_doc_id": "page_de_test.html",
    "annot_id_auteur": "2",
    "anno_startOffset": "107",
    "annot_startContainer": "ident-77",
    "annot_endOffset": "194",
    "annot_forme": "1",
    "annot_value": "crobaties avec ses doigts, mais \u00e9cartons ce cas). Avec un \n  emplacement d\u2019information ",
    "annot_obj": "1",
    "annot_area": "",
    "annot_date": "vendredi 25 juin 2010 10:38:33"
  }
]

But the problem was when i tried ti loop over this json response by using this function, the fonction get excuted just one time, I want to know how to loop over this returned JSON

success: function(data) {
  var mon_selection_2;
  var mon_range;
  resultText = eval(data);
  var resultText_length = resultText.length;
  for (var i = 0; i < resultText_length; i++) {
    mon_selection_2 = window.getSelection();
    mon_selection_2.removeAllRanges();
    mon_range = document.createRange();
    mon_selection_2.addRange(mon_range);
    id_annotation_js = resultText[i].id_annotation;
    anno_startOffset_js = resultText[i].anno_startOffset;
    annot_startContainer_js = resultText[i].annot_startContainer;
    annot_endOffset_js = resultText[i].annot_endOffset;
    annot_value_js = resultText[i].annot_value;
    annot_forme_js = resultText[i].annot_forme;
    var start_Node = document.getElementById(annot_startContainer_js);
    var textNode = start_Node.firstChild;
    mon_range.setStart(textNode, anno_startOffset_js);
    mon_range.setEnd(textNode, annot_endOffset_js);
    var Gras_ele_js = document.createElement("span");
    Gras_ele_js.setAttribute("style", "color:black;font-size:14px;font-weight:bolder");
    Gras_ele_js.setAttribute("value", mon_range);
    Gras_ele_js.setAttribute("id", id_annotation_js);
    mon_range.surroundContents(Gras_ele_js);
  }
}
  • 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-15T11:33:45+00:00Added an answer on May 15, 2026 at 11:33 am

    well, with this line

    resultText = eval(data);
    

    you convert the string into a javascript object. You shouldn’t do it that way (using eval), even if it’s the fastest of all ways, because if massive security reasons.

    You should use jQuerys very own implementation $.parseJSON() or, if available, browsers integrated JSON parser like window.JSON.parse();

    To your question, you need to loop over an object here.

    $.each(resultText, function(i,v)){
       $.each(v, function(index,value){
          anno_startOffset_js = value.anno_startOffset;
          // or anno_startOffset_js = value['anno_startOffset'];
       });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In order to prevent problems when your variable contians someting… May 16, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer If you want them to be really equal (i.e. the… May 16, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer Start with LINQ. It is a core concept in the… May 16, 2026 at 5:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I make an AJAX request to a PHP script which returns a number from
In bottom of my index.php I have a Javascript function between paired <script> tags.
I have a text file that is around 1.7MB that has a list of
I have enabled SSL and I am doing a jQuery AJAX post request and
I have a page that loads a div via AJAX. The AJAX POST call
I have made this mistake several times, and found myself referencing This Post every
I have the following code making a GET request on a URL: $('#searchButton').click(function() {
Hell all, I have made use of the following ignore_user_abort . ignore_user_abort(true); set_time_limit(0); session_start();
I have a win forms application that contains a Web Browser control. I need
I'd to create some transitions between pages. I've made it this way: $(div.fading).css('display', 'none');

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.