469,342 Members | 5,295 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

AJAX page loading

I'm new to AJAX programming (and JavaScript), but I've been picking up
the idea pretty quick. I have a question though. With the project
that I'm working on, I would like to have the main page loaded
dynamicly. Right now, it's just a php script that loads the
information when it's called. But, I can see some problems cropping
up. What I want to do is call the php scripts when the page loads via
JavaScript/AJAX. I'm just not sure what the best way to do this would
be. I was thinking that I could create multiple XMLHttpRequest
objects, and just modify my scripts to use different XMLHttpRequests.
Would this be the best way to do this?

Feb 23 '06 #1
11 14955
pa***********@gmail.com wrote:
I'm new to AJAX programming (and JavaScript), but I've been picking up
the idea pretty quick. I have a question though. With the project
that I'm working on, I would like to have the main page loaded
dynamicly.


Don't to such mistake of changing html by JavaScript!

JavaScript *is* and *should* stay as an aditional feature.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #2
I wasn't planning on using JavaScript to change the html (I'm guessing
you mean an explicit change in the javascript) Or, do you mean (as I
am planning) don't change the html via the XMLHttpRequest object?
This is what I would like to do, idealy:
user gets to main page
basic page is most likely blank, or has very little
using onLoad (probably), call functions to load the information
- these use XMLHttpRequest to call a php script, which does the
work.
the results are then loaded into their respective <div id> tags

Is this what you are saying, don't do?

Feb 23 '06 #3
Jonas Raoni <jo********@gmail.com> wrote in news:dtkqjj$ci4$3
@emma.aioe.org:
pa***********@gmail.com wrote:
I'm new to AJAX programming (and JavaScript), but I've been picking up
the idea pretty quick. I have a question though. With the project
that I'm working on, I would like to have the main page loaded
dynamicly.


Don't to such mistake of changing html by JavaScript!

JavaScript *is* and *should* stay as an aditional feature.


Crazy talk.

It depends on what you are building. If you know your audience, or your
app/page is specific to a type of user, then GO AHEAD!

To suggest that one should not use Javascript to modify the DOM is
outrageous. That's what the DOM is for. Using the two together can bring
real use and LIFE to a web page.

In the web apps I've designed, DOM-manipulation is both helpful and
necessary.

If you know your audience (ie: that they will have javascript enabled), why
limit what you can/can't do with javascript?!?!??!

Feb 23 '06 #4
pa***********@gmail.com wrote:
This is what I would like to do, idealy:
user gets to main page
basic page is most likely blank, or has very little
using onLoad (probably), call functions to load the information
- these use XMLHttpRequest to call a php script, which does the
work.
the results are then loaded into their respective <div id> tags

Is this what you are saying, don't do?


Yeah, people that love JavaScript are totally against using it this way
hehe :)

But I didn't asked you to not use the XHR object, I just said to not
forget the poor browsers and build everything with JavaScript.

You should load everything as pure html and add the JavaScript
behaviours to your content.

Ex of a tree-menu:

1. First load everything as html, forget about JavaScript...
<ul>
Parent Node
<li><a href="deep.abc?parent=1">Child Node A (has children)</a></li>
<li>Child Node B</li>
<li><a href="deep.abc?parent=1">Child Node C (has children)</a></li>
</ul>

2. Parse your menu-structure and add your "AJAX" stuffs to load the
sub-items without refreshing the page.

This way, if the user doesn't have JS enabled, he will be able to
navigate using the simple and always functional html ;]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #5
Good Man wrote:
Jonas Raoni <jo********@gmail.com> wrote in news:dtkqjj$ci4$3
JavaScript *is* and *should* stay as an aditional feature.


Crazy talk.

To suggest that one should not use Javascript to modify the DOM is
outrageous. That's what the DOM is for. Using the two together can bring
real use and LIFE to a web page.


You didn't understood what I said, read the message that I've just sent
to this thread and you'll get my point of view, if you don't agree with
me again, I'll cut my head off hahaha xD
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #6
Ahh, I understand now. The only thing is that there are things that
will need to update. Basicly, I'm making a game, and what I'm talking
about is the main game page (after logging in). The part of the screen
where everything is happening will need to be updated frequently, as
will other things, like menu, and stats. I'm not sure if there is a
good way to get around that, without refreshing the screen.
As for someone getting around if they don't have JS enabled... I don't
think they'd be able to do too much anyway, just because of the nature
of what I was wanting to do, but I could be wrong. Like I said, I'm
new to most of this, so I'm not sure of the capabilities quite yet.

Feb 23 '06 #7
pa***********@gmail.com wrote:
Ahh, I understand now. The only thing is that there are things that
will need to update. Basicly, I'm making a game, and what I'm talking
about is the main game page (after logging in).


[..]

Ah, if it's a JavaScript game, there's no problem, since it requires
JavaScript anyway...

I'm just against "html genocide" on pages that don't really need
JavaScript to work fine. And some people really do such things... This
is what I'm talking about:
<URL:http://rialto.application-servers.com/demoRialto.jsp>.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #8
Dang... I'm new to this, and even I know that's not a good idea. That
could be done so much better with normal HTML and a lot less JS.
Even mine wouldn't be that bad. Mine is mainly just pulling the pages,
maybe a few fun/fancy things, but that can come later.
Back to my original question though, what would be the best way to call
multiple pages like I want? Just have a number of XHRs?

Feb 23 '06 #9
pa***********@gmail.com wrote:
Dang... I'm new to this
You're not alone, me too :]
and even I know that's not a good idea. That
could be done so much better with normal HTML and a lot less JS.
Yeah haha, that's a bizarre project... Turn off the JavaScript, you'll
see nothing but a blank screen. The guy literally done what I can call
"<html><script src="DO-EVERYTHING.js"></script></html>"

But at least here, people love to use those "desktop frameworks", they
come from desktop languages and refuse to learn how the web works.

Back to my original question though, what would be the best way to call
multiple pages like I want? Just have a number of XHRs?


Yes, that's it, a set of requests... Read some links and you'll see that
there are only two ways of requesting data, the asynchronous and the
synchronous way. Choose the asynchronous one, which will allow you to
load the documents at the same time without killing the browser.

The other method stops the script flow until it finishes loading the
request (so imagine what a bad connection can do hehe).
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #10
Guess I'll have to do some programming later tonight then. Thanks for
the tips, and a fun website to gawk at.

Feb 23 '06 #11
Well, I tried something out, but it's not working. I think I need to
go a different route, but I want to check with all of you first.
Here's a rough idea of what I've got:

var http1 = XMLHttpRequest;
var http2 = XMLHttpRequest;

function init()
{
http1Call();
http2Call();
}

The basic idea here is that http1Call, and http2Call, are using their
respective vars.
Now, http1Cal runs. I get data back from it. http2Call does not
though. I've put in alerts in http2Call, and the function it calls, as
well as the ones for http1. I've also put one directly before and
after http2Call. Only the ones IN the functions related to http1 get
used. NONE of the http2 alerts are called.
There are a few possiblities for this. Either I have something wrong,
or there is something in my server config that is only allowing 1
connection. But, I would think that it would queue it up or something.
I'm betting that I have something wrong, considering the alert
inbetween http1Call and http2Call isn't showing up.
Is there something blatenly obvious that I'm missing?

Feb 24 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Eric Wallstedt | last post: by
2 posts views Thread by jason.m.ho | last post: by
1 post views Thread by www.web20developers.com | last post: by
1 post views Thread by geevaa | last post: by
10 posts views Thread by shankwheat | last post: by
11 posts views Thread by =?Utf-8?B?R2VyaGFyZA==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.