I want to get the HTML response page from the cross-domain URL.
for this I am using the ajax request as,
$.ajax({
type: 'GET',
url: "http://wcidevapps.com/salescentral/idisk/0001000383/iDisk",
dataType: "json",
success: function (response) {
$(response).find('li a').each(function () {
listHref.push($(this).attr('href'));
});
}
});
But after requesting it doesn't respond with any result back.
CORS is a mechanism that defines a procedure in which the browser and the web server interact to determine whether to allow a web page to access a resource from different origin. Figure 2. Cross domain ajax request. When you do a cross-origin request, the browser sends Origin header with the current domain value.
For a successful cross-domain communication, we need to use dataType “jsonp” in jquery ajax call. JSONP or “JSON with padding” is a complement to the base JSON data format which provides a method to request data from a server in a different domain, something prohibited by typical web browsers.
Browser does not allow cross domain AJAX requests due to security issues. Cross-domain requests are allowed only if the server specifies same origin security policy. To enable CORS, You need to specify below HTTP headers in the server.
Cross-origin resource sharing (or CORS) can be used to make AJAX requests to another domain.
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
function NameAFunctionName() {
$.ajax({
url: 'http://wcidevapps.com/salescentral/idisk/0001000383/iDisk',
type: 'GET',
dataType: 'json',
headers: {
//WRITE IF THEIR HAVE SOME HEADER REQUEST OR DATA
},
crossDomain: true,
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With