How to load an object form a url?

P

pasparto

Hi All
I am a newbie in javascript so excuse me if the question is so simple.
I have 2 urls that return javascript objects. How can I load these
objects into the objects in my code?

For example when you type url1 in the browser this appears:
{
"id": "123",
"title": "somestuff"
}

and when you type url2 in the browser this appears:
{
"name":"john",
"surname":"smith"
}

Now I want to use these 2 objects in a function in my code, how can i
do that?

Thanks in advance
 
D

David Mark

Hi All
I am a newbie in javascript so excuse me if the question is so simple.
I have 2 urls that return javascript objects. How can I load these
objects into the objects in my code?

For example when you type url1 in the browser this appears:
{
 "id": "123",
 "title": "somestuff"

}

and when you type url2 in the browser this appears:
{
"name":"john",
"surname":"smith"

}

Now I want to use these 2 objects in a function in my code, how can i
do that?

Thanks in advance

I believe there is a basic XHR example in the FAQ.
 
E

Erwin Moller

pasparto schreef:
Hi All
I am a newbie in javascript so excuse me if the question is so simple.
I have 2 urls that return javascript objects. How can I load these
objects into the objects in my code?

For example when you type url1 in the browser this appears:
{
"id": "123",
"title": "somestuff"
}

and when you type url2 in the browser this appears:
{
"name":"john",
"surname":"smith"
}

Now I want to use these 2 objects in a function in my code, how can i
do that?

Thanks in advance

Hi,

You topic is a little confusing: You are not loading an object from an
URL, but from the RESPONSE, so the content you see when you fetch that URL.
(It is possible to store objects in an URL too.)

Judging by the responses you showed us, you are receiving a JSON
response. JSON is a flexible way of sending data from here to there.
(Like XML but much easier and logically if you ask me.)

Have a look here for an introduction:
http://www.json.org/

and here:
http://en.wikipedia.org/wiki/JSON


Regards,
Erwin Moller


--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,129
Messages
2,570,763
Members
47,324
Latest member
RicoBoxer

Latest Threads

Top