0

Hi I am developing Angularjs application. I am trying to call post method but i am not able to call post method.

Below is my code.

app.service("payementservice", function ($http) {
    this.makepayment = function () {
        debugger;
        var validatesecretekeyData = {
            merchant_email: "",//some data
            secret_key: ""//somedata
        };
        var validatesecretekeyUrl = "https://www.paytabs.com/apiv2/validate_secret_key";
        var responseservice = $http.post(validatesecretekeyUrl, validatesecretekeyData).success(function (response) {
        });
        return responseservice;
    }
});

Please find the screenshot here. Post issue

In request header i can see Request Method:OPTIONS but i made POST request? May i know am i doing anything wrong? Any help would be appreciated. Thank you.

Niranjan Godbole
  • 2,055
  • 6
  • 32
  • 72

2 Answers2

0

I think problem isn't in your code - it's about CORS : there is more information : https://stackoverflow.com/a/12112294/6881115

Community
  • 1
  • 1
dasiekjs
  • 76
  • 5
  • Thanks. I have this error in console. Index.html:1 XMLHttpRequest cannot load https://www.paytabs.com/apiv2/validate_secret_key. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:10963' is therefore not allowed access. – Niranjan Godbole May 08 '17 at 11:16
  • Maybe try to use some proxy server in your project, like gulp-connect-proxy, grunt-connect-proxy ? – dasiekjs May 08 '17 at 11:46
  • Okay. So to call other domain always i should use server? – Niranjan Godbole May 08 '17 at 11:48
0

Looks like you are making a cross domain request, angular code doesn't have any problem

madhur
  • 903
  • 1
  • 11
  • 20
  • Thanks. but how can i fix it? – Niranjan Godbole May 08 '17 at 11:20
  • you can have a look here http://stackoverflow.com/questions/23823010/how-to-enable-cors-in-angularjs – madhur May 08 '17 at 11:28
  • Thanks. That dint work. i added some extension to chrome using below link. https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en May i know if this is the right way to fix this? – Niranjan Godbole May 08 '17 at 11:39