Friday, March 29, 2013

disable cache on html5 application

I have developed an android application which continuously get update from a server through AJAX call and there is a PHP file on the server which respond to the AJAX request. My application working properly in localhost. But after i install the application on my android phone, First two or three updates are successfully happens and then after it gives me the historical value( not update).

The problem is the cache. Application hold values on cache and give the cache data when request through AJAX.

I fixed this problem by simply added few codes on the top of my server side PHP file fro disabling the cache. Below is the code.


header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

Wednesday, March 27, 2013

XmlHTTPRequest: “XML Parsing Error: no element found”

I have an html5 application which get details from database through javascript. It is working properly on localhost. But after i move the database to hosting place i get the error XmlHTTPRequest: “XML Parsing Error: no element found”.

This error come because of same origin policy. That mean in my case, database in one host and my application in an another host.

I fix this issue by following steps.(i call database hosting is hostA and my application hosting hostB)

* I have php file on hostA. I add below code to the top of the file.
header('Access-Control-Allow-Origin: *');