Getting Started

  • Revision slug: Talk:AJAX/Getting_Started
  • Revision title: Getting Started
  • Revision id: 101373
  • Created:
  • Creator: Bcarideo
  • Is current revision? No
  • Comment

Revision Content

Just a few notes to make on this...

I am new to this whole AJAX thing, so forgive me if i am pointing out something obvious.

1) When we are calling the open method of the http_request instance (http_request.open()) why are we specifing 'POST' as the HTTP method as the first parameter? Shouldn't it be 'GET' if we are to pass it a URL with a querystring? (as shown in the article)

2) Also, I am confused as to exactly how the server response is to send data back? Will the requested page on the server do processing depending on the data in the querystring it is passed, and then return this data? If so, how is the data passed back? Or does the whole content of a page (eg HTML) get sent back for the JS function to process?

An example of a called page sitting on the server in which the http_request object function is calling would have been useful.

Thanks

Tryst


Hi Tryst,

Re 1) When you POST, you are again sending data from the browser to the server. This data is again formatted as a query string (e.g. "name=value&foo=bar"), only it's not visible in the browser. Well in the case of an XMLHTTPRequest the GETs are also not displayed in the browser, but that was just to clarify.

In any event if you want to post, you'll do:

http_request.open('POST', 'http://example.org/somepage.php', true); http_request.send('name=value&foo=bar');


If you want to GET: http_request.open('GET', 'http://example.org/somepage.php?name=value&foo=bar', true); http_request.send(null);

Re 2)

The server can return HTML or XML that your client-side javascript will handle. It's up to you. If you look at the step 3 in the article, you'll see a way to handle an HTML file returned by the server (http://www.w3clubs.com/mozdev/test.html). Step 4) shows how to handle an XML file returned by the server - http://www.w3clubs.com/mozdev/test.xml

Hope this helps, Stoyan



This code works great in Firefox and Mozilla but IE doesn't seem to want to recognize that thhe XML doc has any children. I've been searching in vain for a solution to get this to work in IE but to no avail. Does anyone know where I might be able to find something on this?

Thanks, Brian

Revision Source

<p>Just a few notes to make on this...
</p><p>I am new to this whole AJAX thing, so forgive me if i am pointing out something obvious.
</p><p>1) When we are calling the open method of the http_request instance (http_request.open()) why are we specifing 'POST' as the HTTP method as the first parameter? Shouldn't it be 'GET' if we are to pass it a URL with a querystring? (as shown in the article)
</p><p>2) Also, I am confused as to exactly how the server response is to send data back? Will the requested page on the server do processing depending on the data in the querystring it is passed, and then return this data? If so, how is the data passed back? Or does the whole content of a page (eg HTML) get sent back for the JS function to process?
</p><p>An example of a called page sitting on the server in which the http_request object function is calling would have been useful.
</p><p>Thanks
</p><p>Tryst
</p>
<hr>
<p>Hi Tryst,
</p><p>Re 1)
When you POST, you are again sending data from the browser to the server. This data is again formatted as a query string (e.g. "name=value&amp;foo=bar"), only it's not visible in the browser. Well in the case of an XMLHTTPRequest the GETs are also not displayed in the browser, but that was just to clarify.
</p><p>In any event if you want to post, you'll do:
</p><p>http_request.open('POST', 'http://example.org/somepage.php', true);
http_request.send('name=value&amp;foo=bar');
</p><p><br>
If you want to GET:
http_request.open('GET', 'http://example.org/somepage.php?name=value&amp;foo=bar', true);
http_request.send(null);
</p><p>Re 2)
</p><p>The server can return HTML or XML that your client-side javascript will handle. It's up to you. If you look at the step 3 in the article, you'll see a way to handle an HTML file returned by the server (http://www.w3clubs.com/mozdev/test.html). Step 4) shows how to handle an XML file returned by the server - http://www.w3clubs.com/mozdev/test.xml
</p><p>Hope this helps,
Stoyan
</p><p><br>
</p>
<hr>
<p>This code works great in Firefox and Mozilla but IE doesn't seem to want to recognize that thhe XML doc has any children.  I've been searching in vain for a solution to get this to work in IE but to no avail.  Does anyone know where I might be able to find something on this?
</p><p>Thanks,
Brian
</p>
Revert to this revision