Mohd -- I recommend you look at how the sample named "Blank Cordova Starter App" is structured. It has lots of comments. You must wait until the devicready (combined into app.Ready in that sample) fires before you run any significant code. Also, if you are relying on the network you will need to restructure your app so it does not rely on a network connection. See the other samples.