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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:51:29+00:00 2026-06-07T03:51:29+00:00

Hi the response i have an JSON : [{id:1,message:sdvsvdsdv,nickname:},{id:2,message:1234556,nickname:},{id:3,message:4555555,nickname:}] The javascript function : function

  • 0

Hi the response i have an JSON :

[{"id":"1","message":"sdvsvdsdv","nickname":""},{"id":"2","message":"1234556","nickname":""},{"id":"3","message":"4555555","nickname":""}]

The javascript function :

function ajax_request(){

var request = new XMLHttpRequest();
var url = "http://localhost/chat/controller.php?showmessage";
request.open("post", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

request.onreadystatechange = function(){
     if(request.readyState == 4 && request.status == 200){

               var return_data = request.responseText; // THE WHOLE JSON

               document.getElementById("chat").innerHTML = return_data;
        }
}
request.send();}

How can i get the element “message” only not the whole JSON ?.

  • 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-07T03:51:31+00:00Added an answer on June 7, 2026 at 3:51 am

    Use JSON.parse("<JSON-STRING>") to get the object out. From the object, you could extract your message.

    Something like:

    var jsonObj = JSON.parse(request.responseText);
    for (var i=0; i<jsonObj.length; i++){
         alert(jsonObj[i].message); //alerts each "message" ..
    }
    

    This is something apart from the actual question, but I would really suggest you to use jQuery library. That takes away half of your efforts. There’s a simple $.ajax(..) to do AJAX requests, and $.parseJSON(..) to parse JSON strings — all in a cross-browser way.

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

Sidebar

Related Questions

I have a code for a comment system. jQuery: function sendComment() { $('#comment_write_area').fadeOut(1); $('#ajax-json-response').fadeOut('fast').html('');
I have the following JSON object: { response: { status: 200 }, messages: [
I have a json response like: { total: 2, success: true, rows: [ {a1_id:7847TK10,
We have a JSON response which can contain null values (e.g. { myValue: null
I have a JSON response that is formatted from my C# WebMethod using the
I have this JSON response string: {d:{\ID_usuario\:\000130\,\Nombre\:null,\Vipxlo\:0,\Provmun\:null,\Descuentos\:null,\Listaviplocal\:null}}` With this code: - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
If i have this json response {error:repeated} Why the alert is not showed? It
Basically, I have a JSON response from the Twitter API containing a timeline. I
I'm developing an android app, and I need to have a json response of
I have a url which have a response in Json lon=-0.1275&pg=0 I parsed 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.