
CodeIgniter Logo
In the Web 2.0 it is familiar to create new services. In Germany the Web 2.0 is also called “Mitmach-Web” (join-in-web). And there is a other transformation in the scene: With Javascript (and that what is called Ajax – I call it in german always “Webwaschmittel”) more and more static websites becomes dynamically web applications – to use like normal desktop applications. But to have an interactive website, which behaves similar to a desktop application (giving response in no time, show informations and take the user into its own hand). The one thing webdesigners and web-developers do to make a website interactive and behaves like an application is to use Javascript. Javascript is the mean of choice but there exists several Javascript-Frameworks which helps the user to write clean and short Javascript-Code with a great functionality.
On the backend-side (server-side) the programmers have done also many development and engineering in the last years. Several Frameworks have been established (Symfony, CodeIgniter, Ruby on Rails, Zend, Flow3 and so on – more about frameworks in the iX special “Web on Rails“). I am using CodeIgniter because it is a really leightweight and nice to use framework with many functionality, but the latitude to program and design your application as you will (means: with very few restrictions and a very small footprint).
In this little HowTo I want to show you how to build a little CodeIgniter REST-like API (only an example with one controller) and use it via Javascript (ajax with jQuery). The REST-API (Representational State Transfer – Advanced Programming Interface) is an idea, a way how to provide information and data as an service to the web, using the HTTP-protocol given mechanisms (like POST-data, GET-data, …). I write knowingly “REST-like”, because it is no easy work to create a full and dynamically usable REST-API. The MVC-Pattern-Design from CodeIgniter helps you to build Controller which can behave REST-like. But still programming a controller and let them return a header and some data is not the whole idea of a REST-full API.
To learn what a REST-API is or how it works: have a look at “A RESTful Web service, an example” by Paul James. There are also a german PDF “REST Web Services – eine Einführung” available from OIO (Orientation In Objects – a german software development company).
I also used two other tutorials from the web to inform myself about form validation with Ajax. You can find them at the end of the article among “Sources”.
Now I want to show you in an easy way how to build one little web service which validates something for you and send a response. A Javascript snippet send a call to the CodeIgniter Controller, the Controller do something and send an response. The answer will be shown up on the front end without relaoding the whole website. So it is good for a site with a PHP-Backend (via the REST-API) because it can be used from others later (maybe from outside or from company-internal services).
Continue reading ‘How to validate forms with jQuery and CodeIgniter’
Letzte Kommentare