AJAX-Tips Tutorials
AJAX-TipsHandling Non-Get Requests
The easiest way of transferring data for an Ajax based application is to use the GET form in XHR. Although there are browser challenges a developer would face, using this function is still the best way to transfer data. Because of browser incompatibility, the workarounds in GET has been relatively easier.
Implementing better security may seem to be a bit hazy for now but as long as the coding is stable and simplified, the application could be easily secured. There are even recommended steps that could be used if a developer wants to integrate JS Client for an API.
But the challenge comes if the developer wants to implement functions that do not use GET. This is usually done by developers who wanted to increase the security of their application by moving away from GET.
The easiest way to transport data is to use POST instead of GET. But that solution will only work if you are working with HTML based applications along with JavaScript. If you are dealing with other programming languages, other commands should be considered. The beauty of additional options is that instead of clinging to a single command of data transport, developers can also implement changes in data such as DELETE, PUT, HEAD, etc.
Using iFrame
The best way to deal with non-GET data transfer in JavaScript is to create a small JS Client that could contact with iFrame. This might sound too drastic since there is another viable solution wherein the non-GET data transfer format would emulate GET only with unlike semantics. But this solution is only good for small applications which might not be feasible when you’re dealing with online application.
Going back to the iFrame, this function would practically become the host for XHR. The client side communication will start at the server, and then go through the iFrame first before continuing to the browser. In a perfect world, you could easily implement iFrame when you are using HTML 5’s window.postMessage function. Unfortunately, the function requires the latest version of browsers which some of the users might not have.
There are two ways in dealing with this problem:
• Create a Small HTML File – The HTML file should be added in the iFrame. When the data request starts with the client side, a small HTML file will be created to receive the data. After the server responses with the data requested, The HTML file will send information to the client side with the details of the command.
• Any File as Initiation – On the other hand, you can consider any file as initiator of the data transfer. Since you already have a JS Client and an iFrame, the file will be used to trigger data transfer requests. When the server has returned with the request the iFrame and the JS Client will have a faster processing because the transaction has already started.
Do take note that it will require a JS Client to enable all these options. Although it will take sometime, the ease of implementation is well worth it.
Sponsored Links
