Jquery Php Cors Example

Post ajax request is not possible with Cross Domain if you don’t use CORS.

Here is an example for Cors.

type: "POST",
url: "http://example.com/user.php",
data: {"name" : "john"},
dataType: "json",
success: function(e){

This is PHP part – user.php

header(‘HTTP/1.0 200’);
header(‘Access-Control-Allow-Methods: "PUT, POST, GET, OPTIONS, DELETE"’);
header(‘Access-Control-Allow-Origin: *’);


You need to define headers. If you don’t define it, you get Server Internal Error (500).