Opt out of website AJAX
There are several different views:
- There are a few out there - I'm afraid I haven't used much, but they cover a lot of plumbing for you and handle X browser compatibility issues.
- jQuery is very commonly used (which is probably useful for your resume).
- ASP.NET AJAX if you are on MS platform.
- Rolling can be enlightening, but you only want to do it for the right reasons.
dependencies
- Which browsers will use the site and what they support, all the old JavaScript compatibility issues with the X browser apply.
- A good structure should help here.
- Be careful how you manage dependencies between client-side and server-side code; you want to ensure consistency as much as possible, and you want to avoid hardcoding and baking in other trash that will do maintenance over time and change a lot.
API / interface design
- Somethings had to handle AJAX calls on the server side: when you create thios, you create an API that you can use for the app (and others), so make sure you think about that a bit.
- Make sure you find useful patterns and design principles: Single Responsibility Principle (SRP), Separating Principle (ISP), General Reuse Principle (CRP)
Safety
- Publishing AJAX APIs on the web has its own set of security, but be careful about them.
- Don't trust the user / system input, make sure you check all the calls made.
- Don't forget that you can protect your API (or parts of it) in a secure area of the site. Authenticated browsers will also be authenticated to use any AJAX interfaces secured in this way.
Documentation
- AJAX by itself does not provide a way to describe itself (for example, via Web services via WSDL); I had a time where a server side interface provided information on how it should be called if it is not being called correctly or allow each interface to be called with a generic "Help" parameter - when called, it returns all the information you need to know. how to call it.
- Your approach will depend on who can use / call the API: is it part of a web application that will only run on companies' local network, or is it related to puiblic / www?
a source to share
I guess this is likely to be a joint tip, so here is one of my experiences.
One of the things I've found when working with AJAX and Internet Explorer is that IE sometimes likes to cache the response for your requests. So if you find that the requests work in Firefox but not IE, that might be the culprit.
Solution, just add an extra parameter to your request url, which will be completely irrelevant in most cases. The parameter can be whatever you want, but the value should be constantly changing and always different, the best solution I have found is to use a date / time stamp as the time is always increasing. For the visual learner, here's an example.
Normal request
http://example.com/controller/action?query=john
IE Job Requests
First request
http://example.com/controller/action?query=john&seed=1234567890
Second request
http://example.com/controller/action?query=john&seed=2345678901
The reason for this is that IE sees it as a new URI, which it never grabbed before it had nothing in it.
a source to share