0

Have a question that I hope can be answered simply.

I have an application on server xxx.yyy.com written in angular.js. It accesses data, via HTTP/JSONP requests, on server abc.def.com.

I want allow my data server to support POST requests from other servers.

In developing this capability, I want to prove out the process where I replace the JSONP request with a POST request. Am now getting CORS errors. I understand what is happening here but I can not figure out a way fix the problem.

In this sample code, on xxx.yyy.com I make this request:

kaunasAPI.simPost = function(meter_data) { URL = 'http://abc.def.com/models/ajx_reading.php'; return $http({ method: 'POST', data: meter_data, url: URL }); } 

On the server abc.def.com I have the following code:

<?php $jTableResult = array(); $jTableResult['Result'] = "OK"; $json = json_encode($jTableResult); exit ( $json ); } ?> 

What am I missing to make this work? Thanks in advance.

1

1 Answer 1

1

Turns out I have been looking for answer on the wrong side, i.e. angular side.

Answer was to add a line to the server code. and the code is now:

<?php { header("Access-Control-Allow-Origin: *"); //Fixes cross origin issue $jTableResult = array(); $jTableResult['Result'] = "OK"; $json = json_encode($jTableResult); exit ( $json ); } ?> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.