jQuery AJAX

Send AJAX requests with this jQuery script.

by Sivasakthi Chandrasekaran

HTML

<script src="http://fonts.googlepis.com/css?famaily=Open+Sans:400,700"></script>
<body><button onclick="loadXMLDoc()">Post call with out authentication</button></body>

JavaScript

function loadXMLDoc() {
var http = new XMLHttpRequest();
var url = "https://nfrel.relevantmobile.com/api/v1/push_services/submit?";
var params = "[email protected]&chain_id=70&service_type=2&select_type=manual_enter&user_ids=350427,350426,350425&reward_id=407&year=2016&month=11&day=13&hour=8&minute=6&time_zone_default=EST";
http.open("POST", url, true);


		'Content-Type: application/json;charset=UTF-8',
		'Access-Control-Allow-Origin': '*',
		'Access-Control-Allow-Methods': 'DELETE, HEAD, GET, OPTIONS, POST, PUT',
		'Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description',
		'Access-Control-Max-Age: 1728000'


//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader('Access-Control-Allow-Origin', '*.*');
http.setRequestHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
http.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Authorization, Content-Length, X-Requested-With');
http.setRequestHeader('Access-Control-Max-Age: 1728000');

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params)
  }