javascript - Unable to bypass CORS in angularjs seed app -


I am using an app and I am trying to get JSON response from server (MarkLogic) $ Http . I was trying to respond to all other similar stackoverfl flow answers for 3 days but it was not able to work, please help!

The browser returns:

  XMLHttpRequest http: // sreddy: 8003 / v1 / search? Format = json can not load The requested resource 'Access-Control-Permission-Origin' header is not present. Origin 'http: // localhost: 8000' is therefore not allowed   

Here is my app code

app.js < / p>

  'strict use'; // Announce the app level module which depends on the filter, and services var app = angular Modules ('My app', ['NGRUT', 'IPFanders', 'Map sources', 'Myep Dannichi's', 'Mauper Controllers']); App.config (['$ routeProvider', '$ httpProvider', function ($ route provider, $ httpProvider) {$ routeProvider.when ('/ view1', {templateUrl: 'partial / partial 1.html', controller: 'MyCtrl1 '}); $ Migration provider (' / visual2 ', {templateUrl:' partial / partial 2.html ', controller:' MyCtrl2 '}); $ routeProvider.otherwise ({redirectTo:' / view1 '}); // $ CODE $ httpProvider.defaults.withCredentials = true; $ httpProvider.defaults.useXDomain = true; $ httpProvider.defaults.headers.common ['X-Requested-With'];}]);   

Administrator.js

  'Strict Use'; / * Controller * / var app = angular. Modules ('myApp.controllers', []); App.controller ('MyCtrl1', ['$ scope', 'dataService', function ($ radius, data service) {$ scope.test = "test"; $ scope.data = null; dataService.getData (). Function (datasource) {$ scope.data = dataResponse;}); console.log ($ scope.data);}]); app.controller ('MyCtrl2', [function () {console.log ("From MyCtrl2");}]);   

services.js

  'strict use'; / * Services * / / Display how to register services // In this case it is a simple value service Var app = angular Module ('myapp.services', []); App.value ('version', '0.1'); app.service ('data service', function ($ http) {this.getData = function () {// $ http () gives a $ promise that we can add handlers along.) then $ http ({method: 'Return') GET ', url:' http: // sreddy: 8003 / v1 / search? Format = json '});}});    

Usage XDomain is not a thing.

You really are having the same basic problem for your request to work, you have to change your header on request. Since you are requesting a simple GET , you should be able to do this, provided it is one. Your content type is likely to flag the request as a CORS request.

Generally - this can be decided by setting your content-type header to application / x -www-form-urlencoded , Multipart / Form-Data , or Text / plain , like this:

  $ Http ({method: 'GET', url: http: // sreddy: 8003 / v1 / search? format = json ', header: {' Content-type ':' text / plain '} // or whatever type}); Or - you can set an interceptor and add headers to all requests that match some criteria.  

For simple requests that you can get, you should do more with request headers, in addition the feedback headings satisfy the preflight request. If you do not have access to the server (to set the response header), then you have to work within their approved parameters. There is more information on the Corse.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -