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 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

Related Questions

I have made a custom ajax script to parse the JSON returned from the
i have a page made AJAX/HTTP Request and the result is JSON formatted .
I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
I have 3 file index.php, .js file, and a.php file. i made a ajax
I make an AJAX request to a PHP script which returns a number from
Suppose I make an AJAX HTTP Request from jQuery to a backend PHP script.
I am adding ajax to this little list web app I made. I have
I have made an AJAX chat using Javascript, PHP, and MySQL. I send the
I have two jQuery AJAX request being made when the use searches for customer
I have made a simple code for ajax to call a page but it

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.