hi ...
while the standard HTTP request makes a 'synchronous' call and must wait for the response and makes a page-reload (you always get a new html-page to display) a XMLHttpRequest may be used sync (not typical) and async (the better way) without a page-reload. you may ask for the response with javascript and the response is usually xml- or json-data that you may process with js and update parts of your page through the use of dom-methods that manipulate your document ... so you don't need an entire page-reload because all of that is running in the 'background' ...
kind regards
Hi,
Thank u moderator...
will u please explain me the clear picture of json-Data..
wat does it mean??
and some sites to get basic knowledge in that...
-Hamsa
10 1595 gits 5,390
Recognized Expert Moderator Expert
hi ...
no problem :) ... have a look at the following example that shows you a typical js-object: - // we create a complex array that contains 3 js
-
// objects
-
var js_obj = [
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'}
-
];
json = javascript object notation and now we get from a, lets say php-json-encoder the following string (as you see it is simply a string that is notated like an native js-obj and only needs to be evaled): - "[
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'}
-
]"
-
with that as a responseText you simply may do: - var data = eval(responseText);
and you get our native js-object in var data ... ok?
kind regards
gits 5,390
Recognized Expert Moderator Expert
hi ... i splitted your JSON-question from the HttpRequest-Thread because i think it may be of interest for more users and so it would be better to find :)
kind regards
hi ...
no problem :) ... have a look at the following example that shows you a typical js-object: - // we create a complex array that contains 3 js
-
// objects
-
var js_obj = [
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'}
-
];
json = javascript object notation and now we get from a, lets say php-json-encoder the following string (as you see it is simply a string that is notated like an native js-obj and only needs to be evaled): - "[
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'}
-
]"
-
with that as a responseText you simply may do: - var data = eval(responseText);
and you get our native js-object in var data ... ok?
kind regards
Hi,
Thank u...I m very new to this...
still it looks greek n latin for me...
ll u please say me still in depth...
will u pl..
-Hamsa
gits 5,390
Recognized Expert Moderator Expert
Hi,
Thank u...I m very new to this...
still it looks greek n latin for me...
ll u please say me still in depth...
will u pl..
-Hamsa
what exactly do you want to know? in the above post you first see a javascript array that has javascript-objects as elements. typical structure of a table ... lets say output of a sql-query. that is what we can handle with javascript ... a javascript-object (i put that to illustrate what we need in js this is what we handle at the client later on -> now we have to get it in any way from the database to the client). but ... the query is done at the server and now we must send its result to the client with a XMLHttpRequest. so the serverside has to encode the result as XML or JSON or whatever ... and when we use JSON-encoding you will send from the server what we see in the second part of the above post. your clientside awaits the responseText and is getting the string i showed you ... we take it, eval it and voila ... we have the js-object we now can handle with javacsript ...
hope this makes it more clear ;)
kind regards
Hi,
Thank u moderator...
will u please explain me the clear picture of json-Data..
wat does it mean??
and some sites to get basic knowledge in that...
-Hamsa
Read this article...very helpfull
http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html
- // we create a complex array that contains 3 js
-
// objects
-
var js_obj = [
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'}
-
];
I'd like to see if I have understood this correctly:
"Without JSON" those variables must have been sent as string, like: -
var js_obj = "$a='value1'; $b='value2';]";
// etc.. (or simple stored in a array like structure)
And then in PHP, split, exploded, implode, foreach, destroy, overkill... (or perhaps evaluated in PHP? I would guess that this would create a security issue if the data is user defined, no?)
json = javascript object notation and now we get from a, lets say php-json-encoder the following string (as you see it is simply a string that is notated like an native js-obj and only needs to be evaled): - "[
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'},
-
{val1: 'value1', val2: 'value2'}
-
]"
-
with that as a responseText you simply may do: - var data = eval(responseText);
and you get our native js-object in var data ... ok?
Because of the fact that eval function evaluates anything, anything sent from the server side could be sent simple as var, array and/or functions, e.g. in PHP
$sendBack = "var HelloCode = 'Hello World'; function alarm(str) {alert(str)};
And then in JavaScript one could just run alarm(HelloCode);
So in conclusion, JSON is a method for sending var, objects and functions to the server side? Have I got it right?
gits 5,390
Recognized Expert Moderator Expert
nope ...
i spoke about exactly the other direction ...
1. our client needs simply js data-structures like i showed with the var js_obj (to illustrate how such an obj looks like)
2. we make an ajax call to the server (GET / POST with required params - may be json too but needn't - in case they are we have to encode them at the client to be send correctly as a string and we mustn't eval there but decode/parse -> security reason and operations overhead ... i wouldn't recommend that) ...
3. the service makes a db-call, gets the result, fetches the lines and creates a php-obj that we now json-ENCODE and send back to the client
4. the client evals the json-response and we have a js-obj like in step 1.
kind regards
nope ...
i spoke about exactly the other direction ...
... I see that I still have some homework to do then. Well, then, maybe my example could work as a deterrent for others.
gits 5,390
Recognized Expert Moderator Expert
... the conclusion could be ... that json is a better method of sending data to the client then XML would be ... because you will process it with js and it is overhead when sending/parsing XML with js ... since you simply may eval a string to have it js-ready with json ...
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: G Matthew J |
last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm
This is more or less in response to Mr Crockford's admonition a few
months ago, "fork if you must". Ironically, although in that usenet
post...
|
by: Luke Matuszewski |
last post by:
Welcome
As suggested i looked into JSON project and was amazed but...
What about cyclical data structures - anybody was faced it in some
project ?
Is there any satisactional recomendation...
...
|
by: Douglas Crockford |
last post by:
There is a new version of JSON.parse in JavaScript. It is vastly
faster and smaller than the previous version. It uses a single call to
eval to do the conversion, guarded by a single regexp test to...
|
by: Kevin Newman |
last post by:
Hello,
I noticed that the JavaScript library for JSON posted on json.org
(http://www.json.org/json.js) is modifying Object.prototype (adding a
method - toJSONString). I thought this was...
|
by: Frank Millman |
last post by:
Hi all
I am writing a multi-user accounting/business application, which uses
sockets to communicate between server and client. The server contains
all the business logic. It has no direct...
| |
by: Red Daly |
last post by:
Hello group,
I have been using JSON for a while and it has made many things a breeze.
However, JSON does not natively describe certain things like pointers
and custom types. I created a simple...
|
by: kungfumike |
last post by:
I am currently having an issue getting json to work. The version of json,js I am using can be found here:
http://www.json.org/json.js
The file is innclided in standard html
<script...
|
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: Lasse Reichstein Nielsen |
last post by:
Max <adsl@tiscali.itwrites:
Not really. It shows that a particularly naïve implementation
of a conversion from XML to JSON doesn't work well.
What if the conversion of
<e>
some
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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...
|
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: 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...
|
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.
| |
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...
| |