XMLHttpRequest cannot load error

144 views
Skip to first unread message

Ivan Bernabucci

unread,
Feb 21, 2014, 5:11:08 AM2/21/14
to ang...@googlegroups.com

Hello, I read about this issue many times but i couldn't get any results even following the suggestions around. I have problems with an application I'm working on that should connect to the API of a remote server.

The GET request I make to the server from Chrome and Firefox (and Fiddler) works perfectly and it gives me back the expected JSON packet

In Angular I tried both:  (sorry I couldn't find a system to format the code)


$http({
     url:urlAddress,
     method:"GET",   
     data: {user: 'xxx', pass: 'xxx', request: 'xxx', key: $scope.query, loc_types: 'xxx'}
 }).success(function(data) {
  console.log('done');
$scope.jex= [];
for (var i = 0; i < data.length; i++) {
        $scope.jex.push(data[i]);
};
}).error(function(r,t,et){
       console.log(r);
console.log(t);
       console.log(et);
});

and

*$http({
  url: requestTo,
  method: "JSONP"
       }).success(function(data) {
console.log(data);
$scope.jex= [];
for (var i = 0; i < data.length; i++) {
$scope.jex.push(data[i]);
};
       }).error(function(r,t,et){
    console.log(r);
    console.log(t);
    console.log(et);
});

In the beginning of my js file I set 

myApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];    
    }
]);

The version with GET gives me back an XMLHtppRequest  - No Access-Control-Allow-Origin error.

The version with JSONP (for wich in the provided URL I added at the end '&callback=JSON_CALLBACK') it gives me back the error' Resource interpreted as Script but transferred with MIME type text/plain'

In this last case when I check Firebug or Chrome Tools, the Response tag shows me the JSON packet sent by the remote server but the console hit the error callback of the http method.

This behavior happens both on my localhost when I try to reach the server and on a remote server where i make tests.

I don't know what to try anymore. Thank you.

Mike Alsup

unread,
Feb 24, 2014, 12:58:00 AM2/24/14
to ang...@googlegroups.com
Please create a plunkr that exhibits your problem so we can better help you.



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Vladimir Varbanov

unread,
Jun 4, 2014, 3:01:51 AM6/4/14
to ang...@googlegroups.com
I have the same problem - do you have any working solution ? 

Sander Elias

unread,
Jun 4, 2014, 3:15:46 AM6/4/14
to ang...@googlegroups.com
Hi Vladimir,

look up CORS

Regards
Sander
Reply all
Reply to author
Forward
0 new messages