Angular restfull call in plnkr 404 - angularjs

Im trying to connect to the openweather api using a factory function in angular. However I get an 404. My link is spot on, but I guess its failing because of the plnkr code in front of the api link
GET http://run.plnkr.co/65ULuFbF2mV8fL2X/api.openweathermap.org/data/2.5/weather?q=London 404 (Not Found)
The test file can be found here:
http://plnkr.co/edit/wstR9oZdYf24jxjru8vS?p=preview
Is there some kind of code or setting to remove the http://run.plnkr.co/65ULuFbF2mV8fL2X/ from the call?

CORS (Cross Origin Resource Sharing) is not supported by the OpenWeatherMap api.
You can take a look at this article to see the reason your code doesn't work: accessing-external-apis-with-angularjs
This means that the OpenWeatherMap API does support CORS. We can try
to access the API via JSONP. $http.jsonp on an API that does not
support CORS, but supports JSONP
I updated your plunker to make it work:
in CONSTANTS.js
LINK: 'http://api.openweathermap.org/data/2.5/weather?q='
in weatherFactory.js
$http.jsonp(config.LINK + city + "&callback=JSON_CALLBACK")
http://plnkr.co/edit/jTYDQlytgIx3jUXQa4MD?p=preview

Related

My API laravel doesn't work when it run on my reactjs

I got a problem, my API laravel doesn't work when it run on my reactjs. When I check, i got failed response data. But,it work fine in postman. Here's my code
This is in reactjs :
This code in ReactJs
and this is in laravel API :
this code in laravel API
i use axios to get response from my API, and i have already set my cors before in my Laravel, just one function can't get response.
here the respons :
response in postman
response in console log react when use chrome
response in network google chrome
I already try to set up cors again and try to change method put to get and put to post, and still doesnt work. I don't know where the problem is.
Maybe you can try to connect with jquery or javascript XMLHttpRequest to make sure where is the problem

Angular CORS works with $http but not with $resource

I am new to angular, using v1.6, I have implemented a basic service for GET requests to communicate with Jetty service on a different host.
After annotating my service endpoints with CrossBorderResourceSharing. I am able to use $http without issues and I can seen the CORS flag in chrome debugger as well.
However $resource does not work gives the CORS error and does not show the CORS flag in debugger either , I am not using any custom settings for both just the basic call.
Let me know if sharing code snippet would help.
You need to enable CORS in the server endpoint.
Add the following to your WEB-INF/web.xml
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>

OPTIONS Error using twitter API (400)

For my personal website, I'd like to create a page summarizing my social presence.
I used Postman to make sure all my queries are valid.
So I made simple call to get my last post on twitter.
Everything works find on Postman, so there isn't any Authorization issues.
But when it comes to implement it on my client (using AngularJs ), I'm getting this error:
OPTIONS https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=1106474965 400 ()
XMLHttpRequest cannot load https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=1106474965. Response for preflight has invalid HTTP status code 400
I know it may be related to How does Access-Control-Allow-Origin header work? but I can't configure the server as I subscribed a shared hosting
(One.com).
I tried to reset my $httpProvider default values in vein.
It seems Twitter API doesn't support CORS headers, and that's why your preflight tests are failing:
https://twittercommunity.com/t/will-twitter-api-support-cors-headers-soon/28276

How to debug a script put in module's config?

My AngularJS project is working with an API. This API provides authentication tokens (Oauth): an access_token and a refresh_token.
Everytime an AngularJS request to the API returns a 401 error, it means that the access_token has expired and it needs to be refreshed by sending the refresh_token to a specific URL. To do that, I followed this tutorial.
But this is not working and I don't know why. I would like to debug the function placed into .config(...) but I don't know how to do that. console.log() and $rootScope = ... doesn't work here.
Thanks for your help !
Use your browser's built-in debugger.
Chrome: https://developer.chrome.com/devtools/docs/javascript-debugging
Firefox: https://developer.mozilla.org/en-US/docs/Tools/Debugger
Firebug: http://getfirebug.com/javascript
IE: https://msdn.microsoft.com/en-us/library/gg699336%28v=vs.85%29.aspx

404 returned in CORS request for some web api calls from angular service

I have an angular application that retrieves data from an ASP.Net web api service.
The web api is hosted on a different domain.
The web api contains multiple URL's to query different types of data, for instance site2/api/Employees, site2/api/Managers, etc.
The web api has a global configuration, as it does normally, i.e. no special configurations are made for any specific controllers.
I have created different controllers in angularjs and for each controller there is a service(copy-pasted code, but I have checked and updated all the necessary references correctly).
When I access site2/api/Employees from my angular code in site1, data is returned from the web api service.
However, when I access /site2/api/Managers from my angular code I get an error OPTIONS:/site2/api/Managers 404 not found
XMLHttpRequest cannot load /site2/api/Managers invalid status code 404
Could someone please,provide a solution for this issue
is i am not angularjs user but i can help you in cors
The cors request works when browsers allow cross-domain request.
One way is to Allow Cors request is through client browser
(jquery) jQuery.support.cors = true this line would be help full if
you are aiming IE Only
For Enabling in other Browser you may check this javscript
Another way is to set HTTP responses header to all access to Cors from server side
below is my php code to all access to Cors through HTTP responses header
<?php
header('Access-Control-Allow-Origin: http://yourdomain.com');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers', 'Content-Type');
i hope this may help you..

Resources