The point is, the call will fail if you fetch a file that isn't valid JSON.
So replace the file with something that's valid and then see if that works.
On Fri, Sep 5, 2014 at 1:21 PM, mark goldin wrote:
> Not sure if it's a valid json, but at this point I dont really care. All I
> want is a wor
Not sure if it's a valid json, but at this point I dont really care. All I
want is a working code.
On Friday, September 5, 2014 3:07:45 PM UTC-5, Eric Eslinger wrote:
>
> I'd take the actual file and shove it through a json linter if I were you,
> or look more closely at the object actually gett
I'd take the actual file and shove it through a json linter if I were you,
or look more closely at the object actually getting returned by the XHR
request (you can see the response in devtools).
On Fri, Sep 5, 2014 at 1:03 PM, mark goldin wrote:
> BAsically, it's something like this:
> { "name"
BAsically, it's something like this:
{ "name": "Hartsfield Jackson Atlanta International Airport", "code":
"ATL", "city": "Atlanta", "state": "GA", "lat": 33.64, "lon": -84.444,
"pop2011": 432427, "vol2011": 44414121, "vol2010": 43130585, "vol2009":
42280868, "vol2008": 43236665, "vol2007": 4323
Show us the contents of the data file please. Looks like a JSON parse error.
On Fri, Sep 5, 2014 at 3:54 PM, mark goldin wrote:
> Controller:
> $http.get(url).then(function (data) { console.log('1234');
> }).catch(function (err) { console.log('5678') });
>
> Tools Console:
> SyntaxError: Unexpe
Controller:
$http.get(url).then(function (data) { console.log('1234');
}).catch(function (err) { console.log('5678') });
Tools Console:
SyntaxError: Unexpected token ,
at Object.parse (native)
at fromJson
(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:1033:14)
at $H
In your controller, just call
$http.get(url).then(function(data){$scope.myData =
data.data}).catch(function(err){console.log(err)});
In simple cases, I prefer just calling $http.get directly. In more
complicated cases, it makes sense to put that behind an abstraction layer
(if you're cache-ing cal
> Jumped to conclusion too quickly. The file is in black now, but the error
> is still there.
>
> On Friday, September 5, 2014 2:06:34 PM UTC-5, mark goldin wrote:
>>
>> That was it! Added it to my web.config and no more errors.
>> Thanks for the help.
>>
>> On Friday, September 5, 2014 1:54:39
Jumped to conclusion too quickly. The file is in black now, but the error
is still there.
On Friday, September 5, 2014 2:06:34 PM UTC-5, mark goldin wrote:
>
> That was it! Added it to my web.config and no more errors.
> Thanks for the help.
>
> On Friday, September 5, 2014 1:54:39 PM UTC-5, Tho
That was it! Added it to my web.config and no more errors.
Thanks for the help.
On Friday, September 5, 2014 1:54:39 PM UTC-5, Thomas Murphy wrote:
>
> I'd be willing to put a bit of money on it throwing a CORS if you're not
> running your angular app against a server.
>
>
>
> On Fri, Sep 5, 2014
Can you please elaborate?
On Friday, September 5, 2014 1:54:39 PM UTC-5, Thomas Murphy wrote:
>
> I'd be willing to put a bit of money on it throwing a CORS if you're not
> running your angular app against a server.
>
>
>
> On Fri, Sep 5, 2014 at 2:50 PM, Eric Eslinger > wrote:
>
>> If the chrom
I'd be willing to put a bit of money on it throwing a CORS if you're not
running your angular app against a server.
On Fri, Sep 5, 2014 at 2:50 PM, Eric Eslinger
wrote:
> If the chrome dev tools are showing a red status, then the error isn't in
> your promise handling, it's in the actual fetch
I agree with that. But again, navigating to the exactly same url in the
Browser shows a file with no problem. I am running IIS on W7 64. Nothing
fancy on that front.
On Friday, September 5, 2014 1:50:31 PM UTC-5, Eric Eslinger wrote:
>
> If the chrome dev tools are showing a red status, then the
If the chrome dev tools are showing a red status, then the error isn't in
your promise handling, it's in the actual fetching of the file - that file
isn't being properly served by your backend, or isn't being served the way
you think it is (you may need to set cookies or a token to access it, etc -
Tools will show the same info even if I try to access non existent file.
On Friday, September 5, 2014 1:43:35 PM UTC-5, mark goldin wrote:
>
> The url is correct, I am not fully showing it.
> In the Tools the file is in Red.Status text Canceled. Can't see any more
> info about failure.
>
> On Fri
Eric is right about promises, but there are times where you want to return
the data from a $http call through the $q promise. For example, we use it
for client-side caching to prevent unnecessary calls to API in the
enterprise app I work on at the moment.
On Fri, Sep 5, 2014 at 2:34 PM, Eric Es
The url is correct, I am not fully showing it.
In the Tools the file is in Red.Status text Canceled. Can't see any more
info about failure.
On Friday, September 5, 2014 1:34:28 PM UTC-5, Eric Eslinger wrote:
>
> You can just treat $http.get() as a promise. You don't have to directly
> instantiat
You can just treat $http.get() as a promise. You don't have to directly
instantiate a second promise unless you're doing something funky.
return $http.get().then(function(data){return
massageData(data)}).catch(function(err){at least you have some error
handling})
Also, if you're getting an error,
Actually I am rather getting alert that says Error.
On Friday, September 5, 2014 12:52:33 PM UTC-5, mark goldin wrote:
>
> Ok, I have changed my code. Here it is:
>
> Service
> angular.module('myModule').factory("service", function ($http, $q) {
>
> var requestUri = 'http://localhost:/localfil
Ok, I have changed my code. Here it is:
Service
angular.module('myModule').factory("service", function ($http, $q) {
var requestUri = 'http://localhost:/localfile.txt';
return {
getData : function(){
var deferred = $q.defer();
var response = $http.get(reque
Great, so let's focus on what's happening in the controller. As Sander
said, you're returning a promise from you service. *That promise needs to
be resolved. *Check out the documentation here on the syntax, and see if it
doesn't provide you the data you're expecting.
https://docs.angularjs.org/api/
1. serviceName.getData();
2. The url points to a text file on the local web server. Navigating from
Browser to the file opens it with no problem.
On Friday, September 5, 2014 9:58:27 AM UTC-5, Thomas Murphy wrote:
>
> 1. What are you doing in the controller once you call
> serviceName.getData()?
1. What are you doing in the controller once you call serviceName.getData()?
2. What url are you calling in $http.get? If you're not calling anything,
you'll get no data.
Best,
Thomas
On Fri, Sep 5, 2014 at 10:49 AM, mark goldin wrote:
> I also found this code:
> function ($http, $q) {
> re
Hi Mark,
You should read in on promises! or watch this flic:
https://www.youtube.com/watch?v=LAJIQWp60QY&index=7&list=UUkQX1tChV7Z7l1LFF4L9j_g
(not on angular, but the promises in there work almost exactly the same.)
the function returns a promise. you should use a .then(function
(incommingD
I also found this code:
function ($http, $q) {
return {
getData : function(){
var deferred = $q.defer();
var promise = $http.get(url).success(function (response) {
deferred.resolve(response);
});
// Return the promise to the
Ok, I see how it works.
Another question. Is it possible to have just one function *MyTestService *and
run it like this?
the result from the service load:
{{vm.data|json}}
On Friday, September 5, 2014 9:28:42 AM UTC-5, mark goldin wrote:
>
> What vm.data shown in index.html wo
What vm.data shown in index.html would come from if I remove the
TestMyService function?
On Friday, September 5, 2014 1:32:11 AM UTC-5, Sander Elias wrote:
>
> Hi Mark,
>
> You mean something like this:
> http://plnkr.co/edit/5cENSfOAhKJDI0iwe6ZV?p=preview
>
> Regards
> Sander
>
--
You receive
Hi Mark,
You mean something like
this: http://plnkr.co/edit/5cENSfOAhKJDI0iwe6ZV?p=preview
Regards
Sander
--
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
28 matches
Mail list logo