0

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am working on an app running on port 7070. Here I want to implement ajax post to the file in my root directory(www/html). So the code I was wrote is as follows. Ajax post

$.ajax({
            type: "POST",
            crossDomain: true,
            data: {patient_id : data},
            url: "url", //http://ipaddress/test/php/filename.php
            success: function(data){
            if(isJson(data))
            {
             // do something 
            }
            }
        }); 

My php file is as follows. Php is located at " www/html/php "

<?php
    $pat_id = $_POST['patient_id'];
    echo "something";
?>

This is returning me an error like this in my chrome console.

XMLHttpRequest cannot load ipaddress/test/php/filename.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'ipaddress:7070' is therefore not allowed access.

But when I attempt the same request from my root directory(by doing ajax post from a file in root directory) it worked.

I tried adding " dataType : jsonp " that doesnt work.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • You should first target the "cannot load" error before figuring out possible CORS problems… – Bergi Jul 04 '14 at 12:06

1 Answers1

-1

Add this line to your web service-

header('Access-Control-Allow-Origin: *');
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90