2017-05-08 113 views
0

嗨我正在開發Angularjs應用程序。我正在嘗試調用post方法,但我無法調用post方法。如何在Angularjs中調用post方法?

以下是我的代碼。

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; 
    } 
}); 

請在這裏找到截圖。 Post issue

在請求頭我可以看到請求方法:選項,但我提出了POST請求?我可以知道我做錯了什麼嗎?任何幫助,將不勝感激。謝謝。

回答

0

我認爲問題不在於你的代碼 - 這是關於CORS:有更多的信息: https://stackoverflow.com/a/12112294/6881115

+0

謝謝。我在控制檯中有這個錯誤。 Index.html:1 XMLHttpRequest無法加載https://www.paytabs.com/apiv2/validate_secret_key。對預檢請求的響應不會通過訪問控制檢查:請求的資源上不存在「Access-Control-Allow-Origin」標頭。原因'http:// localhost:10963'因此不被允許訪問。 –

+0

也許嘗試在你的項目中使用一些代理服務器,如gulp-connect-proxy,grunt-connect-proxy? – dasiekjs

+0

好的。所以要打電話給其他域我總是應該使用服務器? –

0

看起來像您這樣的一個跨域請求,棱角分明的代碼沒有任何問題

+0

謝謝。但我該如何解決它? –

+0

你可以看看這裏http://stackoverflow.com/questions/23823010/how-to-enable-cors-in-angularjs – madhur

+0

謝謝。那力氣工作。我使用下面的鏈接爲Chrome添加了一些擴展。 https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en我可否知道這是否是解決此問題的正確方法? –