POST Request

var contentType ="application/x-www-form-urlencoded; charset=utf-8";
if(window.XDomainRequest)
	contentType = "text/plain";
$.ajax({
 url:"http://hayageektest.appspot.com/cross-domain-cors/post.php",
 data:"name=Ravi&age=12",
 type:"POST",
 dataType:"json",	
 contentType:contentType,	 
 success:function(data)
 {
 	alert("Data from Server"+JSON.stringify(data));
 },
 error:function(jqXHR,textStatus,errorThrown)
 {
 	alert("You can not send Cross Domain AJAX requests: "+errorThrown);
 }
});

GET Request

var contentType ="application/x-www-form-urlencoded; charset=utf-8";
if(window.XDomainRequest)
	contentType = "text/plain";
$.ajax(
{
 url:"http://hayageektest.appspot.com/cross-domain-cors/get.php?name=Ravi&age=32",
 dataType:"json",
 contentType:contentType,	 
 success:function(data)
 {
 	alert("Data from Server"+JSON.stringify(data));
 },
 error:function(jqXHR,textStatus,errorThrown)
 {
 	alert("You can not send Cross Domain AJAX requests : "+errorThrown);
 }
});
Please Share it with your friends: