//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.getEle mentById("txtHi nt").innerHTML= JSONResponse.le ngth; is printing undefined
Please suggest what I am doing wrong in this.
Regards,
5 1750 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 web.xml file, say.
I need to post the whole lot to the server and I'm not sure which is the
best way to do it. It has to be browser-independent. The only ways I can
think of are:
|
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 language="javascript" type="text/javascript">
var book = new Book();
document.write(book.Title);
</script>
Even more, if I could access book through the document object it would
be even more helpful, like:
<script language="javascript"...
|
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. This seems like a good
system because it allows so much freedom in creating the desired
behavior in the browser. The required data doesn't have to be converted
to XML or JSON on the server. The browser doesn't have to have
templates for...
|
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) {
alert('The fatal error occured. Please reload the page.');
return;
|
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 blah
blah. With Ajax (actually, the uncovering of the XmlHTTPRequest
object) I absolutely see the benefit of moving more of the UI work to
the client, rather than doing page refreshes.
I know there are a bunch of libraries out there...
| |
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?
<%@ Language=VBScript %>
<script language="jscript" runat="server">
var json = {"widget":};
</script>
<%
Response.Write json.widget & "<br />"
|
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 JavaScript in response to user actions.
So I'm wanting to translate suitable JSON into HTML elements. I've
looked around a bit and not found anything that does this.
|
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 it). I have
tried it with and without the defer attribute. It will work fine in
firefox, but not IE.
<script type="text/javascript">
function setInnerHTMLAndExecScript (element, html) {
var newElement = element.cloneNode(false);...
|
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 to confirm(yes)/deny(no)/cancel(close UI/cancel submit) their action.
There may be additional JavaScript methods to execute before displaying the UI and may be additional JavaScript methods to execute upon closing the UI.
I'm thinking about...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |