view raw
Abhishek Gupta Abhishek Gupta - 11 months ago 65
jQuery Question

$.post getting canceled in chrome

I am calling a php file using

. From the server I am returning json response. When I open the server url directly in browser it returns successfully. But from js it is not working.
enter image description here
The link I am calling is this(

<script src=""></script>
<input type="button" id="testID">
<script type="text/javascript">
$(document).ready(function() {
$("#testID").click(function() {

I also tried in Firefox. In that I get 200 OK, but no response.

Why this is happening


The problem is that it is a cross domain request the error being returned can be viewed by turning on the javascript console:

XMLHttpRequest cannot load Origin null is not allowed by Access-Control-Allow-Origin.

You will need to make sure that the Access-Control-Allow-Origin headers are set to allow this to happen or Chrome will cancel the request.