Ajax Programming with NetBeans
NetBeans is a free software provided by Sun for programming in multiple languages. It offers advantages for the realization of Ajax applications.
The creation of simple applications or web pages using Ajax is facilitated with features from the version 6.5 of NetBeans:
- CSS editor which allows you to instantly see results of changes.
- Framework manager to install and choose an Ajax library among Yahoo UI, JQuery and many others.
- Visual components to facilitate HTML page creation.
NetBeans also allows you to edit PHP code to make server side scripts.
It is best to configure NetBeans with Firefox for browser (Tools / Options / General). This will provides in addition the Firebug plugin for debugging.
Creating an Ajax project
A basic Web application is created with New Project / Java Web / Web application.
The index.jsp page will be created, and you can use it to develop the Ajax script, you can then rename it and add more pages if necessary.
Then choose the framework, in our example JQuery:
You may need to know where the files are installed, in particular to include the framework in your page. The following tree gives you the file name:
For its physical location, click the right mouse button on the file name, in this case jQuery-1.2.6.js, and open the properties window.
JQuery experts will continue thanks to their experience with the framework. For my part, I had stopped here, failing to find a simple and clear example.
Use your own framework
You can also use a framework that is not in the built-in list of NetBeans, and your own scripts too.
Simply place them in the resources subdirectory. For example, to use the Anaa Ajax framework, unarchive it in resources and keep its directory. The file tree is automatically updated:
Then things become much easier for a first step...
Include the library:
Then we add a minimalist script in the code of the Web page, which comes from the Anaa's archive.
function storing(data, element)
element.innerHTML = data;
} function demo(element)
AARead("resources/anaa/demo-get.txt", storing, element);
} </script> <p> <span id="storage"> ***Must be stored here***. </span> </p>
Type F6 to display the page. Click on the button. The final result is this:
Our first Ajax program with NetBeans works!