Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross domain ajax request

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.

like image 597
Rahul_RJ Avatar asked Mar 18 '13 13:03

Rahul_RJ


People also ask

What is cross domain ajax request?

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.

How do I make a cross domain request in ajax?

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.

Does ajax support cross domain?

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.

Can I send ajax request to another domain?

Cross-origin resource sharing (or CORS) can be used to make AJAX requests to another domain.


1 Answers

<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>
like image 144
Abhisek Das Avatar answered Sep 19 '22 14:09

Abhisek Das