//Outputs:
Hi ,
I am making a application in which I have to send a request using Ajax to ther server and the server return response in JSON .
I just wanna know i am getting the following response from the server: - {"length":50,
-
"accounting":[
-
{"firstName":"John","lastName":"Doe","age":23},
-
{"firstName":"Mary","lastName":"Smith","age":32}],
-
"sales":[
-
{"firstName":"Sally","lastName":"Green","age":27},
-
{"firstName":"Jim","lastName":"Galley","age":41}
-
]}
In JavaScript how i accesss it. Means when I am tring to access it it is saying undefined - if (xmlHttp.readyState==4)
-
{
-
var JSONResponse = xmlHttp.responseText;
-
alert (JSONResponse)
-
document.getElementById("txtHint").innerHTML=JSONResponse.length;
-
}
-
alert is printing - {"length":50,
-
"accounting":[
-
{"firstName":"John","lastName":"Doe","age":23},
-
{"firstName":"Mary","lastName":"Smith","age":32}],
-
"sales":[
-
{"firstName":"Sally","lastName":"Green","age":27},
-
{"firstName":"Jim","lastName":"Galley","age":41}
-
]}
but document.getElementById("txtHint").innerHTML=JSONR esponse.length; is printing undefined
Please suggest what I am doing wrong in this.
Regards,
5 1741 gits 5,390
Recognized Expert Moderator Expert
hi ...
change the line: - var JSONResponse = xmlHttp.responseText;
-
to: - var JSONResponse = eval(xmlHttp.responseText);
kind regards
hi ...
change the line: - var JSONResponse = xmlHttp.responseText;
-
to: - var JSONResponse = eval(xmlHttp.responseText);
kind regards
Now it is showing error expected ';' at - var JSONResponse = eval(xmlHttp.responseText);
gits 5,390
Recognized Expert Moderator Expert
so you have to show what you have done besides that, because when you test the following: - var test = eval({"length":50,
-
"accounting":[
-
{"firstName":"John","lastName":"Doe","age":23},
-
{"firstName":"Mary","lastName":"Smith","age":32}],
-
"sales":[
-
{"firstName":"Sally","lastName":"Green","age":27},
-
{"firstName":"Jim","lastName":"Galley","age":41}
-
]});
-
-
alert(test.length);
it alerts 50 as expected.
kind regards
gits 5,390
Recognized Expert Moderator Expert
glad to hear that :) ... post back to the forum anytime you have more questions ...
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andy Fish |
last post by:
Hi,
I have a webpage with some javascript that constructs some data structures,
some of which contain nested structures or arrays of other structures. It's
the same order of complexity as a...
|
by: andrei.csibi |
last post by:
I've have a .NET Assembly, which is COM Visible. I would like to load
objects from this assembly in javascript code. E.g. Assembly Book.dll
has the class Book and I would like to use
<script...
|
by: petermichaux |
last post by:
Hi,
Some servers return JavaScript as the response to an AJAX request. When
the response JavaScript is eval'ed it calls other JavaScript functions
already in the browser to update elements, etc....
|
by: Ralph |
last post by:
Hi
I have problem converting JSON string to an array. The best way to
explain this is to show you some code. So :
try {
var response = that.AjaxReq.responseText.parseJSON();
} catch (myErr)...
|
by: Tom Cole |
last post by:
While I've done javascript work for as long as I can remember (since
Netscape first released it), I've only ever used it for trivial
things, change a color here, validate a text element there, blah...
| |
by: Marc |
last post by:
I'm aware that there are significant differences between VBScript objects
and JScript objects but that doesn't mean something like the following
should give me such troubles?
<%@...
|
by: Jonathan Fine |
last post by:
Hello
I want to provide a mini-help system on a web page, to help the user
when s/he is filling in a form.
I thought I'd hold the help data in JSON format, and translate it to
HTML via...
|
by: cantrell78 |
last post by:
I can't for the life of me figure out how to execute javascript inside
of div that was set using innerHTML or in my case using cloneNode and
replaceChild (not my idea to do this, I'm just fixing...
|
by: Frinavale |
last post by:
Apparently I have a lot of questions today regarding JavaScript security.
I've implemented a JavaScript Object that intercepts page submits (postbacks) and then displays a UI prompting the user...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |