Rest api calls from the game

Hie,

Is there a way to call rest apis from the game in cocos html library.

Can i use simple ajax requsts using jquery or do i need to use xhrhttprequest within the game to call to api?

Any sample program would be highly helpful?

Maybe this helps, but this is how we post stats to another server. We create a utilities JS file and include it in our cocos2d.js file.

Javascript example

        
	function sendPostRequest(options) {
	    var http = new XMLHttpRequest();
	    var request_url = 'http://yourrequesturl.com/api/';

	    var params = '';
	    if (options.params) {
		    for (var key in options.params) {
				params += '&' + key + '=' + options.params[key];
			}
	    }
		
	    http.open("POST", request_url + options.url, true);
	    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
	    http.onreadystatechange = function() {
	        var httpStatus = http.statusText;
	        if (http.responseText) {
		        var responseJSON = eval('(' + http.responseText + ')');
	        } else {
		        var responseJSON = {};
	        }
			
			
			switch (http.readyState) {
				case 4:
					if (options.success) options.success(responseJSON);
			}
	    };
	    http.send(params.substr(1));
	}