Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

Cordova: Introduction to AJAX

AJAX stands for Asynchronous Javascript And XML. It is a client-side script used in Javascript to communicate with server to exchange data or anything without refreshing the page.

Let us suppose we want to make a dynamic cordova based application where user needs to exchange data with server, say login credential verification, so we can use AJAX to send the data to the server and through the same gateway server, send the result back to the user.

Ajax basic code: We will use jquery.

$.ajax is a jQuery function to make http POST, GET etc request to the server and receive results without the page being refreshed or reloaded.

    type : 'get',	//Request method: GET, POST  
    url : 'http://studytonight.php/login.php',  //Where to send the data
    data: {name, password},  //What data you want to send
    success:function(data) {  
        //Here you will receive data from server
        //Do what you want to do with data                         
        console.log(data)	 //This is a example, like we want to print the result

NOTE: Covering Ajax and jQuery is not in the scope of this tutorial. But we strongly advice you to learn abour Ajax, as it is very useful if you want to create dynamic Apps.