कैसे AngularJS यहाँ के माध्यम से वेब सेवा करने के लिए JSON डेटा पोस्ट करने के लिए बाकी वेब सेवा करने के लिए JSON डेटा पोस्ट करने के लिए कोड का टुकड़ाकैसे AngularJS
.controller('MessagePostCtrl', function($scope, $http) {
$scope.postMessage = function() {
var msg = document.getElementById('message').value;
var msgdata = {
message : msg
};
var res = $http.post('http://<domain-name>/messenger/api/posts/savePost',msgdata);
res.success(function(data, status, headers, config) {
console.log(data);
});
}
})
विकल्प है http/savePost
ionic.bundle.js: 16,185 (अनाम समारोह) ionic.bundle.js: 16,185 sendReq ionic.bundle.js: 15,979 serverRequest ionic.bundle.js: 15,712 wrappedCallback ionic.bundle.js: 19197 wrappedCallback ionic.bundle.js: 1 9 1 9 7 (अनाम कार्य) ionic.bundle.js: 1 9 283 स्कोप। $ Eval ionic.bundle.js: 20326 स्कोप। $ Digest ionic.bundle.js: 20138 स्कोप। $ Ionic.bundle.js लागू करें: 20430 (अनाम कार्य) ionic.bundle.js: 43025 (अनाम कार्य) ionic.bundle.js: 10,478 foreach ionic.bundle.js: 7950 eventhandler ionic.bundle.js: 10477 triggerMouseEvent ionic.bundle.js: 2648 tapClick ionic.bundle.js: 2637 tapMouseUp ionic.bundle.js: 2707XMLHttpRequest http: /// मैसेंजर/एपीआई/पोस्ट/सेवपोस्ट लोड नहीं कर सकता है। अमान्य HTTP स्थिति कोड 404
लेकिन जब मैं $ http.post विधि से msgdata निकालने के लिए, सब कुछ ठीक काम कर रहा है। किसी को भी मुझे बता सकते हैं जहां मुद्दा है वरना मेरे गाइड मदद
**Edited:
The Issue was with the CORS, Im using codeigniter REST Controller for web-services.
Modified the headers. If anyone has the same issue add the below header in the construct
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
if ("OPTIONS" === $_SERVER['REQUEST_METHOD']) {
die();
}
Thanks to Linial for the break-through, telling me where the issue is.**
क्या आपकी webservice JSON या फ़ॉर्म डेटा की अपेक्षा करता है? (उदा: "संदेश = परीक्षण और एक्स = test2") –
webservice केवल JSON प्रारूप –