Monday, 8 September 2014
Memory Analyzer Blog: Automated Heap Dump Analysis: Finding Memory Leaks...
Memory Analyzer Blog: Automated Heap Dump Analysis: Finding Memory Leaks...: There is a common understanding that a single snapshot of the Java heap is not enough for finding a memory leak. The usual approach is to se...
Memory Analyzer Blog: Heap Dump Analysis with Memory Analyzer, Part 2: S...
Memory Analyzer Blog: Heap Dump Analysis with Memory Analyzer, Part 2: S...: In the second part of the blog series dedicated to heap dump analysis with Memory Analyzer (see previous post here ) I will have a detailed...
Memory Analyzer Blog: Heap Dump Analysis with Memory Analyzer, Part 1: H...
Memory Analyzer Blog: Heap Dump Analysis with Memory Analyzer, Part 1: H...: Almost two years passed since the Memory Analyzer tool (MAT) was published at Eclipse. Since then we have collected a lot of feedback, ques...
Tuesday, 10 June 2014
Android Development: iPhone like Tabs in Android.
Android Development: iPhone like Tabs in Android.: Hi all! While developing Android application we needed Iphone like tab bar at the bottom of the screen, so Googled and find usefull links ...
Android Development: Android ListView with Speech Bubble
Android Development: Android ListView with Speech Bubble: Hi, Android Speech Bubble example Today I'm going to discuss how to make a ListView with speech bubble same as native android me...
Saturday, 21 December 2013
How to make CORS request in Javascript and Jquery.
Here I included a basic tutorial for making CORS(Corss Origin Resource Sharing) request from Javascript and Jquery.
1.Include Jquery library on your page.
2.See below code which is fully functional for CORS request.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js"></script>
<script>
// Create the XHR object.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
// Helper method to parse the title tag from the response.
function getTitle(text) {
return text.match('<title>(.*)?</title>')[1];
}
// Make the actual CORS request.
function makeCorsRequest() {
// All HTML5 Rocks properties support CORS.
var url = 'http://updates.html5rocks.com';
var xhr = createCORSRequest('GET', url);
if (!xhr) {
alert('CORS not supported');
return;
}
// Response handlers.
xhr.onload = function() {
var text = xhr.responseText;
var title = getTitle(text);
alert('Response from CORS request to ' + url + ': ' + title);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.send();
}
function jqueryCorsRequest(){
$.ajax({
// The 'type' property sets the HTTP method.
// A value of 'PUT' or 'DELETE' will trigger a preflight request.
type: 'GET',
// The URL to make the request to.
url: 'http://updates.html5rocks.com',
// The 'contentType' property sets the 'Content-Type' header.
// The JQuery default for this property is
// 'application/x-www-form-urlencoded; charset=UTF-8', which does not trigger
// a preflight. If you set this value to anything other than
// application/x-www-form-urlencoded, multipart/form-data, or text/plain,
// you will trigger a preflight request.
contentType: 'text/plain',
xhrFields: {
// The 'xhrFields' property sets additional fields on the XMLHttpRequest.
// This can be used to set the 'withCredentials' property.
// Set the value to 'true' if you'd like to pass cookies to the server.
// If this is enabled, your server must respond with the header
// 'Access-Control-Allow-Credentials: true'.
withCredentials: false
},
headers: {
// Set any custom headers here.
// If you set any non-simple headers, your server must include these
// headers in the 'Access-Control-Allow-Headers' response header.
},
success: function(data) {
// Here's where you handle a successful response.
alert("Success: "+data);
},
error: function(error) {
// Here's where you handle an error response.
// Note that if the error was due to a CORS issue,
// this function will still fire, but there won't be any additional
// information about the error.
alert("Error: "+error);
}
});
}
</script>
</head>
<body>
<input name="" type="button" value="Create Cors Request" onclick="makeCorsRequest();" /><br />
<input name="" type="button" value="Jquery Cors Request" onclick="jqueryCorsRequest();"/>
</body>
</html>
1.Include Jquery library on your page.
2.See below code which is fully functional for CORS request.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js"></script>
<script>
// Create the XHR object.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
// Helper method to parse the title tag from the response.
function getTitle(text) {
return text.match('<title>(.*)?</title>')[1];
}
// Make the actual CORS request.
function makeCorsRequest() {
// All HTML5 Rocks properties support CORS.
var url = 'http://updates.html5rocks.com';
var xhr = createCORSRequest('GET', url);
if (!xhr) {
alert('CORS not supported');
return;
}
// Response handlers.
xhr.onload = function() {
var text = xhr.responseText;
var title = getTitle(text);
alert('Response from CORS request to ' + url + ': ' + title);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.send();
}
function jqueryCorsRequest(){
$.ajax({
// The 'type' property sets the HTTP method.
// A value of 'PUT' or 'DELETE' will trigger a preflight request.
type: 'GET',
// The URL to make the request to.
url: 'http://updates.html5rocks.com',
// The 'contentType' property sets the 'Content-Type' header.
// The JQuery default for this property is
// 'application/x-www-form-urlencoded; charset=UTF-8', which does not trigger
// a preflight. If you set this value to anything other than
// application/x-www-form-urlencoded, multipart/form-data, or text/plain,
// you will trigger a preflight request.
contentType: 'text/plain',
xhrFields: {
// The 'xhrFields' property sets additional fields on the XMLHttpRequest.
// This can be used to set the 'withCredentials' property.
// Set the value to 'true' if you'd like to pass cookies to the server.
// If this is enabled, your server must respond with the header
// 'Access-Control-Allow-Credentials: true'.
withCredentials: false
},
headers: {
// Set any custom headers here.
// If you set any non-simple headers, your server must include these
// headers in the 'Access-Control-Allow-Headers' response header.
},
success: function(data) {
// Here's where you handle a successful response.
alert("Success: "+data);
},
error: function(error) {
// Here's where you handle an error response.
// Note that if the error was due to a CORS issue,
// this function will still fire, but there won't be any additional
// information about the error.
alert("Error: "+error);
}
});
}
</script>
</head>
<body>
<input name="" type="button" value="Create Cors Request" onclick="makeCorsRequest();" /><br />
<input name="" type="button" value="Jquery Cors Request" onclick="jqueryCorsRequest();"/>
</body>
</html>
Subscribe to:
Posts (Atom)