Archive for the 'Understanding AJAX' Category

Understanding AJAX shipping from Amazon and Available at book stores

Wednesday, September 6th, 2006

Understanding AJAX has finally made its way through the supply chain and is shipping from online places. I’ve even heard its available at book stores but I haven’t had a chance to see it in one yet. I’ll be stopping by one after work to grab some pictures.

Understanding AJAX example code now available

Wednesday, August 23rd, 2006

All the code shown in Understanding AJAX is now available from understandingajax.net. You can run the examples on my server or download them and set them up on your own. If you run into any problems leave a comment on this post.

Understanding AJAX excerpt available at computerworld.com

Tuesday, August 22nd, 2006

The lead story at ComputerWorld.com is an excerpt from my book Understanding AJAX. If you are thinking about buying the book, but needed more information to make a decision nows your chance. Head over to ComputerWorld read the chapter, check out the table of contents, and then pick up the book at Amazon or your favorite book seller.

Updates:
The computerworld excerpt has been dugg, add your diggs if your interested in helping it spread. You can also get the article in PDF format from the publishers website if you’d rather take a look at the chapter in a layout like the final product.

Understanding AJAX reviews and Table of Contents

Thursday, August 17th, 2006

I’ve added the Table of Contents to this site, so if your wondering more about the topics covered in the book, thats a good place to start.

I’ve also added a reviews section that links to reviews of the book, the first one is already out from AP Lawrence who got a copy of the pre-release manuscript.

Let me know if you review Understanding AJAX so I can add it too my list.

AJAX Answers

Thursday, August 17th, 2006

The last couple days have been a lot of fun. I was at LinuxWorld and did a book signing yesterday, my publisher had the first copies of Understanding AJAX at their booth. They should be showing up at bookstores and Amazon in the next couple weeks.

Your AJAX answers from my AJAX questions post are below, I hope everyone finds them helpful.

Dealing with broken connections

Question:

How can I find out whether a connection is broken? Should I just set a unique timeout per request after which an error message can be displayed? The timeout would be deactivated if the AJAX call succeeds. Is this a smart idea and does it work?

Answer:

Using a timeout per request does work though its not a perfect solution. HTML_AJAX uses this approach, and a default timeout of 20 seconds. The issue is that 20 seconds is a long time to wait to provide an error, but there are still cases that hit this value. Its also hard to know what to do if you’ve hit an error, is this a transient failure and you should resend your request, or can you know longer talk to the server and you’re app needs to provide and error.

HTML_AJAX vs Prototype

Question:

Why would you want to use HTML_AJAX when there are far better tools for the job, pure javascript solutions such as prototype or jquery? I don’t think you need something special on the serverside to return some data as a response to an AJAX call.

Answer:

I guess you don’t like HTML_AJAX, which is ok, but there are lots of reasons why developers want AJAX libraries that are closely tied to there server side language. Libraries like HTML_AJAX make it easy to perform RPC style AJAX, and they usually make it possible to write less JavaScript on just focus on your primary server side language. Though these libraries do this to varying degrees of success. Something like SAJAX just handles the RPC, while HTML_AJAX can be used with very limited JavaScript writing (HTML_AJAX_Action stuff), and most of the .NET AJAX libraries allow you to add AJAX with no JavaScript at all, since the .NET code behind concept make its really easy to automatically chunk up your code.
Even if there is a JavaScript library you think its great, that doesn’t mean it offers the tools that everyone wants.

Degradable AJAX sites and JavaScript behaviors

Question:

What is the best way to ‘degrade’ a website when Javascript/XMLHttpRequest support is disabled? Take f.e. yahoo.com. It’s a great website enriched with AJAX, but when JS is disabled it’s still looks the same but the rich features are not there. Would you consider CSS-style selectors as the solution? I do not want to create two different websites, one JS enabled and the other JS disabled. Thank you in advance.

Answer:

CSS-style selectors, like those you use with the Behavior library gives you a good tool to write a degradable AJAX site, but the actual implementation can be pretty hard.

In general it means fully implementing a site without AJAX, then picking forms, links, etc that you want to make AJAX and tieing the AJAX too them at runtime. This works really well if your just doing something like type-ahead search since your not changing work flows, but it doesn’t always work that great for form submissions, since they often update different parts of the page, and the code that processes them is generally designed to build the whole page.

If your using AJAX for enhancements that don’t change the actual work flow then making your site degrable is easy. If your site relies on AJAX for its basic workflow you’ll have a much harder time making a site degrade.

Attaching JavaScript using css selectors is a great approach since it keeps your HTML completly seperate

Adding JavaScript on using AJAX

Question:

When utilizing an AJAX API such as Google Maps, how do you execute embedded Javascript commands in a page generated on-the-fly? For example, you have a website which contains several ’s, one of which is an implementation of the API (i.e. a Google map). That loads when the page loads. Now, based on user interaction (clicking on links), you pull an SQL result from a database and display 10 at a time in a separate . Each time the loads, you want to execute some commands through the AJAX API. In my understanding, JS only executes at the browser page load, but I’m sure I’ve seen sites that get around this.

Answer:

While its true that you can’t directly add JavaScript too a page using script tags and innerHTML, that doesn’t mean you can’t add JavaScript to your page at any time. The simplest way is too just send your new JavaScript as text and run it through eval too add it too the page. You can also parse your strings before adding them with innerHTML and run eval as nesseccary. HTML_AJAX provides a method for doing this parsing for HTML_AJAX_Util.setInnerHTML. If you use it JavaScript in any script tags will be run. Other libraries like prototype also offer similar features.

AJAX File Upload

Question:

how can i make a file upload via ajax?

Answer:

If you think of AJAX as involving using XMLHttpRequest then you can’t (at least not without disabling the browsers security model, which i don’t even recommend for intranet apps). But you can still upload files asyncronously, its just a matter of targeting a form at a hidden iframe. You will also want to look at generating your IFrame in JS since i believe it gives you less problems with browser history.

AJAX Form Submission

Question:

I’ve been studying AJAX for a bout a month now but I have not yet grasped the tecnique to submit a form with POST method. I’ve been trying to find an article that covered that but all I could find was the ones that included somekind of already made framework.

I want to know how to submit data to server (like form or email sending) with POST method.

Answer:

Submit a POST request using AJAX you first have to understand what a normal form POST is.
When you submit a form in your browser it makes a http request with the following options:
HTTP Verb: POST
Content-Type: application/x-www-form-urlencoded
And a body of something like:
fielda=valuea&fieldb=valueb

So to replicate a form POST in AJAX you need to run xmlhttp.open with POST set a header, xmlhttp.setRequestHeader(‘Content-type’,'application/x-www-form-urlencoded’);

Then encode your content and send it.
xmlhttp.send(‘fielda=valuea&fieldb=valueb’);

If you use a library most have code for handling this for you, HTML_AJAX has HTML_AJAX.formSubmit for taking a form and submitting it using AJAX and HTML_AJAX.post for doing custom POSTs.

You got AJAX questions I got Answers

Friday, August 11th, 2006

Have you wondered whats the easiest way to submit a form using AJAX, what the status of HTML_AJAX development is, or what is covered in Understanding AJAX?

Well nows your chance.

Submit your questions general AJAX questions, questions about my soon to be released book Understanding AJAX, questions on HTML_AJAX, or anything else I might know the answer of, and I’ll answer them in another post a couple days from now.

Understanding AJAX Digital Shortcut Available

Thursday, August 3rd, 2006

A chapter from my book, Understanding AJAX has been made available as a digital shortcut. This chapter covers the different ways you can use the data you transfer using XMLHttpRequest.

Document centric approaches based on HTML and XML are described as well as various RPC approaches are shown.

Personally i tend to use JSON based RPC approaches or HTML document based approaches. Document based HTML approaches let you add AJAX support without radically changing your development model, since its just a matter of breaking your pages into small chunks and generating HTML just like normal. RPC approaches allow you to develop JavaScript driven apps, which is great for quick prototyping and small apps, since you can write a backend in PHP and have it made immediatly accessible (at least if you use a library like HTML_AJAX to do the work for you) to your HTML and JavaScript frontend.

In Clearhealth we use both approaches. JavaScript widgets like our patient selector make RPC requests. While screens like the claim editor make standard HTTP POSTs treating each form section like it is its own page.

I don’t do much work with AJAX and XML, but client side XSLT can be a good solution if you need to move lots of data since it tends to scale better to extremly large datasets (especially in IE).

If your interested in the details of these various approaches grab the digital shortcut or pickup Understanding AJAX.

Understanding AJAX went to the Printer

Thursday, July 27th, 2006

The milestone i’ve been waiting for has finally happened.

My book went to the printer yesterday at 3:30 p.m

Understanding AJAX Cover Complete

Tuesday, July 25th, 2006

I just signed off on the finished Understanding AJAX cover.

Its exciting to be so close to having the finished book.

AzPHP has a meeting tonight, hope too see you there.

Book Progress

Wednesday, July 12th, 2006

I’ll my copy editing reviewing is finally done. I’m in the process of reviewing layout right now and getting the last of the fixes sent in.

Understanding AJAX is really close to getting done. Also i should have a full table of contents to post in the next couple weeks.

Understanding AJAX Milestone

Wednesday, June 28th, 2006

As a birthday present to myself I finished my last writing task (an Appendix containing AJAX libraries) on my book, Understanding AJAX.

The only thing I have left now is too review copy editing on the preface and appendixes and the back cover of the book.

Oh and I have to promote the book, and get the examples in a ready to ship state.

I’t feels like i’m in college again

Friday, June 23rd, 2006

Not paying enough attention to dates I left myself 8 chapters of copy editing review to do in one night. The good news is I got it all done, which means all the heavy lifting for the book is done.

The bad news is i’ve been editing for 7 or 8 hours straight. The fun never ends.

Well thats not true, soon my part of the book creation will be done.

And then i get to setup demo’s advertise it, hmm a books the gift that keeps on giving :-)

I’ve been away, but I’m back

Sunday, June 11th, 2006

As you may have noticed I haven’t been bloggiing much lately, but there are a couple good reasons why.

First I’m getting married, planning the wedding tends to take a bit of time.

Second i’ve been working really hard to get a book about AJAX done.

The book is finally into production and I’m just starting to get some chapters back from the copy editor.

I do have one thing to share with you today, the books cover.
The complete title is: Understanding AJAX: Using JavaScript to Create Rich Internet
Applications
The ISBN is 0132216353

Understanding AJAX book cover

Also im still finishing up the books appendices which list AJAX libraries, so if you know of AJAX libs for various languages please let me know, im especially interested in AJAX libs for C#, Java, Perl, and Python I already keep up pretty good with all the PHP ones, and most of the non backend language specific ones.

This circle expands additional navigation