Jquery Cors Example - Jquery

How to send cross domain AJAX requests in jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

CORS is abbreviated as Cross Origin Resource Sharing. It is done by setting response headers in the servers. Due to security risks browsers will not allow cross domain AJAX requests. Cross domain requests are allowed only if the server is in same origin security. The output will be obtained only when the requested page is present in that domain.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $.ajax({ url:"http://www.demo.org/ajax.php", data:"name=hscriptsampdomain=com", type:"POST", dataType:"json", 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); } }); }); </script>

Tags


Ask Questions

Ask Question