Data
Data
Data
DOCTYPE html>
<html itemscope itemtype="http://schema.org/QAPage">
<head>
<title>javascript - Getting Json data from text file in AngularJS - Stack Overfl
ow</title>
<link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/
img/favicon.ico?v=4f32ecc8f43d">
<link rel="apple-touch-icon image_src" href="https://cdn.sstatic.net/Sites/s
tackoverflow/img/apple-touch-icon.png?v=c78bd457575a">
<link rel="search" type="application/opensearchdescription+xml" title="Stack
Overflow" href="/opensearch.xml">
<meta name="twitter:card" content="summary">
<meta name="twitter:domain" content="stackoverflow.com"/>
<meta property="og:type" content="website" />
<meta property="og:image" itemprop="image primaryImageOfPage" content="https
://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded
" />
<meta name="twitter:title" property="og:title" itemprop="title name" content
="Getting Json data from text file in AngularJS" />
<meta name="twitter:description" property="og:description" itemprop="descrip
tion" content="I am new to AngularJS and trying to fetch JSON data from a text f
ile:
Here is my HTML:
&lt;div ng-controller="customersController as custCont"&gt;
&lt;ul&gt;
&lt;li ng-repeat="x in names"&..." />
<meta property="og:url" content="http://stackoverflow.com/questions/28387312
/getting-json-data-from-text-file-in-angularjs"/>
<link rel="canonical" href="http://stackoverflow.com/questions/28387312/gett
ing-json-data-from-text-file-in-angularjs" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.
js"></script>
<script src="https://cdn.sstatic.net/Js/stub.en.js?v=9a8031813907"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/s
tackoverflow/all.css?v=d9243128ba1c">
<link rel="alternate" type="application/atom+xml" title="Feed for qu
estion 'Getting Json data from text file in AngularJS'" href="/feeds/que
stion/28387312">
<meta name="twitter:app:country" content="US" />
<meta name="twitter:app:name:iphone" content="Stack Exchange iOS" />
<meta name="twitter:app:id:iphone" content="871299723" />
<meta name="twitter:app:url:iphone" content="se-zaphod://stackoverfl
ow.com/questions/28387312/getting-json-data-from-text-file-in-angularjs" />
<meta name="twitter:app:name:ipad" content="Stack Exchange iOS" />
<meta name="twitter:app:id:ipad" content="871299723" />
<meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow
.com/questions/28387312/getting-json-data-from-text-file-in-angularjs" />
<meta name="twitter:app:name:googleplay" content="Stack Exchange And
roid">
<meta name="twitter:app:url:googleplay" content="http://stackoverflo
w.com/questions/28387312/getting-json-data-from-text-file-in-angularjs">
<meta name="twitter:app:id:googleplay" content="com.stackexchange.ma
rvin">
<script>
StackExchange.ready(function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.initSnippetRenderer();
});
StackExchange.using("postValidation", function () {
StackExchange.postValidation.initOnBlurAndSubmit($('#post-fo
rm'), 2, 'answer');
});
StackExchange.question.init({showAnswerHelp:true,totalCommentCou
nt:7,shownCommentCount:5,highlightColor:'#F4A83D',backgroundColor:'#FFF',questio
nId:28387312});
styleCode();
StackExchange.realtime.subscribeToQuestion('1', '28387312');
StackExchang
e.using("gps", function () { StackExchange.gps.trackOutboundClicks('#content', '
.post-text', true); });
});
</script>
<script>
StackExchange.init({"locale":"en","stackAuthUrl":"https://stackauth.com"
,"networkMetaHostname":"meta.stackexchange.com","serverTime":1487750098,"routeNa
me":"Questions/Show","site":{"name":"Stack Overflow","description":"Q&A for prof
essional and enthusiast programmers","isNoticesTabEnabled":true,"recaptchaPublic
Key":"6LdchgIAAAAAAJwGpIzRQSOFaO0pU6s44Xt8aTwc","recaptchaAudioLang":"en","enabl
eNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"e
nableInsertDocLinkDialog":true,"enableSocialMediaInSharePopup":true},"user":{"fk
ey":"32f537db8d8fdb741b40766678f99977","rep":0,"isAnonymous":true,"isAnonymousNe
tworkWide":true,"canSeeNewHeaderDesign":true,"ab":{"question_show_tweaks":{"v":"
altern_unansw_cta","g":1},"devstory_timeline_exp":{"v":"b","g":2}}},"events":{"p
ostType":{"question":1},"postEditionSection":{"title":1,"body":2,"tags":3}},"sto
ry":{"minCompleteBodyLength":75}}, {"site":{"allowImageUploads":true,"enableUser
Hovercards":true,"styleCode":true,"enableNewLinkInsertDialog":true,"enableImgurH
ttps":true,"forceHttpsImages":true},"comments":{},"userProfile":{"openGraphAPIKe
y":"58740831ad23540e00c58987"},"tags":{},"accounts":{"currentPasswordRequiredFor
ChangingStackIdPassword":true},"flags":{"allowRetractingFlags":true},"analytics"
:{"clientTimingsAbsoluteTimeout":30000,"clientTimingsDebounceTimeout":1000},"sni
ppets":{"snippetsEnabled":true,"renderDomain":"stacksnippets.net"},"markdown":{"
asteriskIntraWordEmphasis":true}});
StackExchange.using.setCacheBreakers({"js/prettify-full.en.js":"1d4fb582
14d2","js/moderator.en.js":"cbd9a328c047","js/full-anon.en.js":"2e47f3ab48cc","j
s/full.en.js":"fa16c4607c6f","js/wmd.en.js":"c174aa372284","js/third-party/jquer
y.autocomplete.min.js":"d3b8fa7fdf74","js/third-party/jquery.autocomplete.min.en
.js":"","js/mobile.en.js":"8c3bd5e12250","js/help.en.js":"a9d821110060","js/tage
ditor.en.js":"09862381cd28","js/tageditornew.en.js":"f156c9e5639f","js/inline-ta
g-editing.en.js":"2ddfa79492e7","js/revisions.en.js":"8f22ba768cac","js/review.e
n.js":"5d553af24c51","js/tagsuggestions.en.js":"b278f9a0b23b","js/post-validatio
n.en.js":"18263d352841","js/explore-qlist.en.js":"e71f14781288","js/events.en.js
":"9253044075ec","js/keyboard-shortcuts.en.js":"837880f5819d","js/external-edito
r.en.js":"cb487078c372","js/adops.en.js":"9a6a7812a212","js/external-editor.en.j
s":"cb487078c372","js/snippet-javascript.en.js":"11b9273bb631","js/snippet-javas
cript-codemirror.en.js":"e0babbb9bd6a"});
StackExchange.using("gps", function() {
StackExchange.gps.init(true);
});
</script>
<script>
StackExchange.ready(function () {
$('#nav-tour').click(function () {
StackExchange.using("gps", function() {
StackExchange.gps.track("aboutpage.click", { aboutclick_
location: "headermain" }, true);
});
});
});
</script>
</head>
<body class="question-page new-topbar">
<noscript><div id="noscript-padding"></div></noscript>
<script>(function () { var old = $.fn.contents; $.fn.contents = func
tion () { try { return old.apply(this, arguments); } catch (e) { return $([]); }
} })()</script>
<iframe id="adzerk-user-match" width="0" height="0" frameborder="0" scro
lling="no" onload="window.AUMIframeDone=true"
src="https://ssum-sec.casalemedia.com/usermatch?s=183712&cb=
https%3A%2F%2Fengine.adzerk.net%2Fudb%2F22%2Fsync%2Fi.gif%3FpartnerId%3D1%26user
Id%3D"
style="display: none;" marginheight="0" marginwidth="0"></iframe
>
<div id="notify-container"></div>
<div id="custom-header"></div>
<header class="so-header js-so-header _fixed">
<div class="-container">
<div class="-main">
<a href="/" class="-logo " >
<span class="-img">Stack Overflow</span>
</a>
<nav class="navigation">
<ol class="-list">
<li class="-item _current">
<a id="nav-questions" href="/questions" class="-link js-gps-track"
data-gps-track="top_nav.click({is_current:true, location:2, destinat
ion:1})">Questions</a>
</li>
<li class="-item">
<a id="nav-jobs" href="/jobs?med=site-ui&ref=jobs-tab" class="-link
js-gps-track"
data-gps-track="top_nav.click({is_current:false, location:2, destina
tion:6})">Jobs</a>
</li>
<li class="-item">
<a id="nav-docs" href="/documentation" class="-link js-gps-track"
data-gps-track="top_nav.click({is_current:false, location:2, destina
tion:7})">Documentation <small class='beta-badge'>beta</small></a>
</li>
<li class="-item">
<a id="nav-tags" href="/tags" class="-link js-gps-track"
data-gps-track="top_nav.click({is_current:false, location:2, destina
tion:2})">Tags</a>
</li>
<li class="-item">
<a id="nav-users" href="/users" class="-link js-gps-track"
data-gps-track="top_nav.click({is_current:false, location:2, destina
tion:3})">Users</a>
</li>
</ol>
</nav>
<form id="search" action="/search" method="get" class="searchbar" au
tocomplete="off">
<svg viewBox="0 0 18 18" width="18" height="18" role="icon"><pat
h fill-rule="evenodd" d="M12.864 11.32h-.813l-.288-.277A6.66 6.66 0 0 0 13.38 6.
69a6.69 6.69 0 1 0-6.69 6.69 6.66 6.66 0 0 0 4.354-1.617l.278.288v.813L16.467 18
18 16.467l-5.136-5.146zm-6.174 0a4.625 4.625 0 0 1-4.632-4.63A4.625 4.625 0 0 1
6.69 2.058a4.625 4.625 0 0 1 4.63 4.632 4.625 4.625 0 0 1-4.63 4.63z"/></svg>
<input name="q" type="text" placeholder="Search..." value="" tab
index="1" autocomplete="off" maxlength="240" class="f-input js-search-field" />
<button type="submit" class="btn js-search-submit">
<svg viewBox="0 0 18 18" width="18" height="18" role="icon">
<path fill-rule="evenodd" d="M12.864 11.32h-.813l-.288-.277A6.66 6.66 0 0 0 13.3
8 6.69a6.69 6.69 0 1 0-6.69 6.69 6.66 6.66 0 0 0 4.354-1.617l.278.288v.813L16.46
7 18 18 16.467l-5.136-5.146zm-6.174 0a4.625 4.625 0 0 1-4.632-4.63A4.625 4.625 0
0 1 6.69 2.058a4.625 4.625 0 0 1 4.63 4.632 4.625 4.625 0 0 1-4.63 4.63z"/></sv
g>
</button>
</form>
</div>
<div class="-actions">
<nav class="secondary-nav">
<div class="-dialog-container js-topbar-dialog-corral">
<a href="http://meta.stackoverflow.com"
class="site-link js-gps-track"
data-id="552"
data-gps-track="site.switch({ target_site:552, item_type:3 }),site_switch
er.click({ item_type:4 })">
<div class="site-icon favicon favicon-stackoverflowmeta" title="Meta Sta
ck Overflow"></div>
Meta Stack Overflow
</a>
</li>
</ul>
</div>
<div class="header" id="your-communities-header">
<h3>
your communities </h3>
</div>
<div class="modal-content" id="your-communities-section">
<div class="call-to-login">
<a href="https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl
=%2fusers%2fstory%2fcurrent&amp;utm_source=stackoverflow.com&amp;utm_med
ium=dev-story&amp;utm_campaign=signup-redirect" class="login-link js-gps-tra
ck" data-gps-track="site_switcher.click({ item_type:10 })"
>Sign up</a> or <a href="https://stackoverflow.com/users/login?ssrc=site_switche
r&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f28387312%2fgetting-
json-data-from-text-file-in-angularjs" class="login-link js-gps-track" data-
gps-track="site_switcher.click({ item_type:11 })"
>log in</a> to customize your list.
</div>
</div>
<div class="header">
<h3><a href="//stackexchange.com/sites">more stack exchange communit
ies</a>
</h3>
<a href="http://stackoverflow.blog" class="fr">company blog</a>
</div>
<div class="modal-content">
<div class="child-content"></div>
</div>
</div>
<div class="topbar-dialog help-dialog js-help-dialog dno">
<div class="modal-content">
<ul>
<li>
<a href="/tour" class="js-gps-track" data-gps-track="hel
p_popup.click({ item_type:1 })">
Tour
<span class="item-summary">
Start here for a quick overview of the site
</span>
</a>
</li>
<li>
<a href="/help" class="js-gps-track" data-gps-track="help_po
pup.click({ item_type:4 })">
Help Center
<span class="item-summary">
Detailed answers to any questions you might have
</span>
</a>
</li>
<li>
<a href="//meta.stackoverflow.com" class="js-gps-tra
ck" data-gps-track="help_popup.click({ item_type:2 })">
Meta
<span class="item-summary">
Discuss the workings and policies of this si
te
</span>
</a>
</li>
<li>
<a href="http://stackoverflow.com/company/about" cla
ss="js-gps-track" data-gps-track="help_popup.click({ item_type:6 })">
About Us
<span class="item-summary">
Learn more about Stack Overflow the company
</span>
</a>
</li>
<li>
<a href="https://www.stackoverflowbusiness.com/?ref=
topbar_help" class="js-gps-track" data-gps-track="help_popup.click({ item_type:7
})">
Business
<span class="item-summary">
Learn more about hiring developers or postin
g ads with us
</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<ol class="-list">
<li class="-item"><a href="#" class="-link js-help-button" title="Help Cente
r and other resources">
<svg viewBox="0 0 18 18" width="18" height="18" role="icon"><path fill-r
ule="evenodd" d="M9 0a9 9 0 1 0 .001 18.001A9 9 0 0 0 9 0zm.812 13.126c-.02.716-
.55 1.157-1.238 1.137-.659-.02-1.177-.49-1.157-1.209.02-.715.566-1.17 1.225-1.15
.691.021 1.194.507 1.17 1.222zm1.956-5.114c-.168.237-.546.542-1.02.912l-.527.361
c-.257.197-.417.43-.502.695-.044.141-.076.507-.084.752-.004.048-.032.156-.181.15
6H7.883c-.165 0-.185-.096-.18-.144.023-.667.12-1.218.397-1.66.374-.594 1.426-1.2
21 1.426-1.221.161-.12.286-.25.382-.39.177-.24.321-.51.321-.8 0-.333-.08-.65-.29
3-.915-.249-.31-.518-.458-1.036-.458-.51 0-.808.257-1.021.594-.213.338-.177.735-
.177 1.097H5.746c0-1.366.357-2.238 1.112-2.752.51-.35 1.162-.502 1.921-.502.996
0 1.788.184 2.487.715.647.49.988 1.181.988 2.113 0 .575-.2 1.057-.486 1.447z" />
</svg>
</a></li>
<li class="-item">
<a href="//stackexchange.com" class="-link js-site-switcher-button js-gp
s-track" data-gps-track="site_switcher.show" title="A list of all 165 Stack Exch
ange sites">
<svg viewBox="0 0 18 19" width="18" height="19" role="icon"><path fi
ll-rule="evenodd" d="M0 14a2 2 0 0 0 2 2h10v3l3-3h1a2 2 0 0 0 2-2v-2H0v2zM16 0H2
a2 2 0 0 0-2 2v2h18V2a2 2 0 0 0-2-2zM0 6h18v4H0V6z" /></svg>
</a>
</li>
</ol>
</nav>
<div class="-ctas">
<a href="https://stackoverflow.com/users/login?ssrc=head&ret
urnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f28387312%2fgetting-json-data
-from-text-file-in-angularjs" class="login-link btn-clear" rel="nofollow">Log In
</a>
<a href="https://stackoverflow.com/users/signup?ssrc=hea
d&returnurl=%2fusers%2fstory%2fcurrent&utm_source=stackoverflow.com&utm_
medium=dev-story&utm_campaign=signup-redirect" class="login-link btn" rel="n
ofollow">Sign Up</a>
</div>
</div>
</div>
</header>
<script>
StackExchange.ready(function () { StackExchange.topbar.init(); });
StackExchange.scrollPadding.setPaddingTop(60, 10); </script>
<div class="container">
<div class="aside-cta">
<a href="/questions/ask" class="btn-outlined">Ask Question</a>
</div>
</div>
<div id="mainbar">
<div class="vote">
<input type="hidden" name="_id_" value="28387312">
<a class="vote-up-off" title="This question shows research effort; it is
useful and clear">up vote</a>
<span itemprop="upvoteCount" class="vote-count-post ">1</span>
<a class="vote-down-off" title="This question does not show any research
effort; it is unclear or not useful">down vote</a>
<a class="star-off" href="#">favorite</a>
<div class="favoritecount"><b>1</b></div>
</div>
</td>
<td class="postcell">
<div>
<div class="post-text" itemprop="text">
<p>I am new to AngularJS and trying to fetch JSON data from a text file:</p>
<p>Here is my HTML:</p>
<pre><code><div ng-controller="customersController as custCont">
<ul>
<li ng-repeat="x in names">
{{ x.Name + ', ' + x.Country }}
</li>
</ul>
</div>
</code></pre>
<p>Whereas my controller is as given below:</p>
<pre><code>app.controller( "customersController", function( $scope, $window) {
$http({
url: 'test.txt',
dataType: 'json',
method: 'POST',
data: '',
headers: {
"Content-Type": "application/json"
}
}).success(function(response){
$scope.names = response;
}).error(function(error){
$scope.names = 'error';
});
</code></pre>
<p>This doesn't show anything. Now if I replace the above http request with test
.txt data assigned to $scope.names then it starts working: I mean, something lik
e this:</p>
<pre><code>$scope.names = [
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbkp",
"City" : "Lule",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"City" : "Mxico D.F.",
"Country" : "Mexico"
},
{
"Name" : "Ernst Handel",
"City" : "Graz",
"Country" : "Austria"
},
{
"Name" : "FISSA Fabrica Inter. Salchichas S.A.",
"City" : "Madrid",
"Country" : "Spain"
},
{
"Name" : "Galera del gastrnomo",
"City" : "Barcelona",
"Country" : "Spain"
},
{
"Name" : "Island Trading",
"City" : "Cowes",
"Country" : "UK"
},
{
"Name" : "Kniglich Essen",
"City" : "Brandenburg",
"Country" : "Germany"
},
{
"Name" : "Laughing Bacchus Wine Cellars",
"City" : "Vancouver",
"Country" : "Canada"
},
{
"Name" : "Magazzini Alimentari Riuniti",
"City" : "Bergamo",
"Country" : "Italy"
},
{
"Name" : "North/South",
"City" : "London",
"Country" : "UK"
},
{
"Name" : "Paris spcialits",
"City" : "Paris",
"Country" : "France"
},
{
"Name" : "Rattlesnake Canyon Grocery",
"City" : "Albuquerque",
"Country" : "USA"
},
{
"Name" : "Simons bistro",
"City" : "Kbenhavn",
"Country" : "Denmark"
},
{
"Name" : "The Big Cheese",
"City" : "Portland",
"Country" : "USA"
},
{
"Name" : "Vaffeljernet",
"City" : "rhus",
"Country" : "Denmark"
},
{
"Name" : "Wolski Zajazd",
"City" : "Warszawa",
"Country" : "Poland"
}
];
</code></pre>
<p>The text file obviously contains all the data except the first row (i.e.
<code>$scope.names = [</code> and the last semicolon<code>;</code></p>
<p>That means the $http request to test.txt is failing which is in the same fold
er as html and js files. Anyone can please help.</p>
<p>Thanks.</p>
<p><strong>======= UPDATE ========</strong></p>
<p>There were two issues. </p>
<ol>
<li>I missed $http parameter in my controller function.</li>
<li>I was using "POST", which I replaced with "GET" to make it work</li>
</ol>
<p>It now work from local machine as well as remote web server.</p>
<p>Thanks for all your help.</p>
</div>
<div class="post-taglist">
<a href="/questions/tagged/javascript" class="post-tag" title="show ques
tions tagged 'javascript'" rel="tag">javascript</a> <a href="/questions/
tagged/json" class="post-tag" title="show questions tagged 'json'" rel="
tag">json</a> <a href="/questions/tagged/angularjs" class="post-tag" title="show
questions tagged 'angularjs'" rel="tag">angularjs</a> <a href="/questio
ns/tagged/text" class="post-tag" title="show questions tagged 'text'" re
l="tag">text</a> <a href="/questions/tagged/xmlhttprequest" class="post-tag" tit
le="show questions tagged 'xmlhttprequest'" rel="tag">xmlhttprequest</a>
</div>
<table class="fw">
<tr>
<td class="vt">
<div class="post-menu"><a href="/q/28387312" title="short permalink to this ques
tion" class="short-link" id="link-post-28387312">share</a><span class="lsep">|</
span><a href="/posts/28387312/edit" class="suggest-edit-post" title="">improve t
his question</a></div>
</td>
<td align="right" class="post-signature">
<div class="user-info ">
<div class="user-action-time">
<a href="/posts/28387312/revisions" title="show all edits to this post">
edited <span title="2015-02-07 21:34:55Z" class="relativetime">Feb 7 '15 at 21:3
4</span></a>
</div>
<div class="user-gravatar32">
</div>
<div class="user-details">
<div class="-flair">
</div>
</div>
</div> </td>
<td class="post-signature owner">
<div class="user-info ">
<div class="user-action-time">
asked <span title="2015-02-07 20:59:49Z" class="relativetime">Feb 7 '15
at 20:59</span>
</div>
<div class="user-gravatar32">
<a href="/users/3103244/anjum"><div class="gravatar-wrapper-32"><img src
="https://www.gravatar.com/avatar/82f2464fd0ab8abec849aeddc54714a0?s=32&d=id
enticon&r=PG&f=1" alt="" width="32" height="32"></div></a>
</div>
<div class="user-details">
<a href="/users/3103244/anjum">Anjum</a>
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">1
,003</span><span title="14 silver badges"><span class="badge2"></span><span clas
s="badgecount">14</span></span><span title="34 bronze badges"><span class="badge
3"></span><span class="badgecount">34</span></span>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-28387312" class="comments ">
<table>
<tbody data-remaining-comments-count="2"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
<a name="28387519"></a>
<div id="answer-28387519" class="answer accepted-answer" data-answerid="28387519
" itemscope itemtype="http://schema.org/Answer" itemprop="acceptedAnswer">
<table>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" name="_id_" value="28387519">
<a class="vote-up-off" title="This answer is useful">up vote</a>
<span itemprop="upvoteCount" class="vote-count-post ">4</span>
<a class="vote-down-off" title="This answer is not useful">down vote</a>
<td class="answercell">
<div class="post-text" itemprop="text">
<p>You are missing to define $http as a parameter</p>
<pre><code>app.controller( "customersController", function( $scope, $window, $ht
tp) {
</code></pre>
<p>Also make sure you are testing in a web server. You cann't make ajax request
from file:// protocol</p>
<p>Also change your request from POST to GET and it should work fine. <a href="h
ttp://plnkr.co/edit/Lh9sYyTRjWziN1ZEg29t?p=preview" rel="nofollow">Here is a Pun
klr</a></p>
<pre><code> method: 'GET',
</code></pre>
</div>
<table class="fw">
<tr>
<td class="vt">
<div class="post-menu"><a href="/a/28387519" title="short permalink to this answ
er" class="short-link" id="link-post-28387519">share</a><span class="lsep">|</sp
an><a href="/posts/28387519/edit" class="suggest-edit-post" title="">improve thi
s answer</a></div> </td>
<td align="right" class="post-signature">
<div class="user-info ">
<div class="user-action-time">
<a href="/posts/28387519/revisions" title="show all edits to this post">
edited <span title="2015-02-07 21:36:07Z" class="relativetime">Feb 7 '15 at 21:3
6</span></a>
</div>
<div class="user-gravatar32">
</div>
<div class="user-details">
<div class="-flair">
</div>
</div>
</div> </td>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-28387519" class="comments ">
<table>
<tbody data-remaining-comments-count="1"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
<script>
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
</script>
<script>
StackExchange.ready(function() {
initTagRenderer("".split(" "), "".split(" "));
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
</script>
</div>
<div style="position: re
lative;">
<div
class="form-item dno new-post-login">
<div class="new-login-form">
<div class="new-login-left">
<h3>Sign up or <a id="login-link" href="/users/login?ssr
c=question_page&returnurl=http%3a%2f%2fstackoverflow.com%2fquestions%2f28387312%
2fgetting-json-data-from-text-file-in-angularjs%23new-answer">log in</a></h3>
<script>
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-l
ink');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window
.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height(
);
if ((docViewTop < elemTop) && (docViewBo
ttom > elemBottom)) {
StackExchange.using('gps', function(
) { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_p
age' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
</script>
<div class="preferred-login google-login">
<p><span class="icon"></span><span>Sign up using Goo
gle</span></p>
</div>
<div class="preferred-login facebook-login">
<p><span class="icon"></span><span>Sign up using Fac
ebook</span></p>
</div>
<div class="preferred-login stackexchange-login">
<p><span class="icon"></span><span>Sign up using Ema
il and Password</span></p>
</div>
</div>
<input type="hidden" name="manual-openid" class="manual-open
id" />
<input type="hidden" name="use-facebook" class="use-facebook
" value="false" />
<input type="hidden" name="use-google" class="use-google" va
lue="false" />
<input type="button" class="submit-openid" value="Submit" st
yle="display:none" />
<div class="new-login-right">
<h3>Post as a guest</h3>
<div class="form-item">
<table>
<tr>
<td class="vm">
<div>
<label for="display-name">Name</label>
<input id="display-name" name="display-name" type="text" siz
e="30" maxlength="30" value="" tabindex="105">
</div>
<div>
<label for="m-address">Email</label>
<input id="m-address" name="m-address" type="email" size="30
" maxlength="100" value="" tabindex="106" placeholder="required, but never shown
" />
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<script>
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'h
ttp%3a%2f%2fstackoverflow.com%2fquestions%2f28387312%2fgetting-json-data-from-te
xt-file-in-angularjs%23new-answer', 'question_page');
}
);
</script>
<noscript>
<h3>Post as a guest</h3>
<div class="form-item">
<table>
<tr>
<td class="vm">
<div>
<label for="display-name">Name</label>
<input id="display-name" name="display-name" type="text" siz
e="30" maxlength="30" value="" tabindex="105">
</div>
<div>
<label for="m-address">Email</label>
<input id="m-address" name="m-address" type="email" size="30
" maxlength="100" value="" tabindex="106" placeholder="required, but never shown
" />
</div>
</td>
</tr>
</table>
</div>
</noscript>
</div>
</div>
</div>
<div id="footer" class="categories">
<div class="footerwrap">
<div id="footer-menu">
<div class="top-footer-links">
<a href="http://stackoverflow.com/company/about">about us</a
>
<a href="/tour">tour</a>
<a href="/help">help</a>
<a href="http://stackoverflow.blog?blb=1">blog</a>
<a href="http://chat.stackoverflow.com">chat</a>
<a href="http://data.stackexchange.com">data</a>
<a href="http://stackexchange.com/legal">legal</a>
<a href="http://stackexchange.com/legal/privacy-policy">priv
acy policy</a>
<a href="http://stackoverflow.com/company/work-here">work he
re</a>
<a href="https://www.stackoverflowbusiness.com/advertise">ad
vertising info</a>
<a href="http://stackoverflow.com/jobs/directory/develop
er-jobs">developer jobs directory</a>
<a onclick='StackExchange.switchMobile("on")'>mobile</a>
<b><a href="/contact">contact us</a></b>
<b><a href="http://meta.stackoverflow.com">feedback</a><
/b>
</div>
<div id="footer-sites">
<table>
<tr>
<th colspan=3>
Technology
</th>
<th >
Life / Arts
</th>
<th >
Culture / Recreation
</th>
<th >
Science
</th>
<th >
Other
</th>
</tr>
<tr>
<td>
<ol>
<li><a href="//stackoverflow.com" title="professional an
d enthusiast programmers">Stack Overflow</a></li>
<li><a href="//serverfault.com" title="system and networ
k administrators">Server Fault</a></li>
<li><a href="//superuser.com" title="computer enthusiast
s and power users">Super User</a></li>
<li><a href="//webapps.stackexchange.com" title="power u
sers of web applications">Web Applications</a></li>
<li><a href="//askubuntu.com" title="Ubuntu users and de
velopers">Ask Ubuntu</a></li>
<li><a href="//webmasters.stackexchange.com" title="pro
webmasters">Webmasters</a></li>
<li><a href="//gamedev.stackexchange.com" title="profess
ional and independent game developers">Game Development</a></li>
<li><a href="//tex.stackexchange.com" title="users of Te
X, LaTeX, ConTeXt, and related typesetting systems">TeX - LaTeX</a></li>
<li><a href="//softwareengineering.stackexchange.com" ti
tle="professionals, academics, and students working within the systems developme
nt life cycle who care about creating, delivering, and maintaining software resp
onsibly">Software Engineering</a></li>
<li><a href="//unix.stackexchange.com" title="users of L
inux, FreeBSD and other Un*x-like operating systems">Unix & Linux</a></li>
<li><a href="//apple.stackexchange.com" title="power use
rs of Apple hardware and software">Ask Different (Apple)</a></li>
<li><a href="//wordpress.stackexchange.com" title="WordP
ress developers and administrators">WordPress Development</a></li>
</ol></td><td><ol>
<li><a href="//gis.stackexchange.com" title="cartographe
rs, geographers and GIS professionals">Geographic Information Systems</a></li>
<li><a href="//electronics.stackexchange.com" title="ele
ctronics and electrical engineering professionals, students, and enthusiasts">El
ectrical Engineering</a></li>
<li><a href="//android.stackexchange.com" title="enthusi
asts and power users of the Android operating system">Android Enthusiasts</a></l
i>
<li><a href="//security.stackexchange.com" title="inform
ation security professionals">Information Security</a></li>
<li><a href="//dba.stackexchange.com" title="database pr
ofessionals who wish to improve their database skills and learn from others in t
he community">Database Administrators</a></li>
<li><a href="//drupal.stackexchange.com" title="Drupal d
evelopers and administrators">Drupal Answers</a></li>
<li><a href="//sharepoint.stackexchange.com" title="Shar
ePoint enthusiasts">SharePoint</a></li>
<li><a href="//ux.stackexchange.com" title="user experie
nce researchers and experts">User Experience</a></li>
<li><a href="//mathematica.stackexchange.com" title="use
rs of Wolfram Mathematica">Mathematica</a></li>
<li><a href="//salesforce.stackexchange.com" title="Sale
sforce administrators, implementation experts, developers and anybody in-between
">Salesforce</a></li>
<li><a href="//expressionengine.stackexchange.com" title
="administrators, end users, developers and designers for ExpressionEngine®
CMS">ExpressionEngine® Answers</a></li>
<li><a href="//crypto.stackexchange.com" title="software
developers, mathematicians and others interested in cryptography">Cryptography<
/a></li>
</ol></td><td><ol>
<li><a href="//codereview.stackexchange.com" title="peer
programmer code reviews">Code Review</a></li>
<li><a href="//magento.stackexchange.com" title="users o
f the Magento e-Commerce platform">Magento</a></li>
<li><a href="//dsp.stackexchange.com" title="practitione
rs of the art and science of signal, image and video processing">Signal Processi
ng</a></li>
<li><a href="//raspberrypi.stackexchange.com" title="use
rs and developers of hardware and software for Raspberry Pi">Raspberry Pi</a></l
i>
<li><a href="//codegolf.stackexchange.com" title="progra
mming puzzle enthusiasts and code golfers">Programming Puzzles & Code Golf</
a></li>
<li>
<a href="http://stackexchange.com/sites#technology"
class="more">
more (7)
</a>
</li>
</ol>
</td>
<td>
<ol>
<li><a href="//photo.stackexchange.com" title="professio
nal, enthusiast and amateur photographers">Photography</a></li>
<li><a href="//scifi.stackexchange.com" title="science f
iction and fantasy enthusiasts">Science Fiction & Fantasy</a></li>
<li><a href="//graphicdesign.stackexchange.com" title="G
raphic Design professionals, students, and enthusiasts">Graphic Design</a></li>
<li><a href="//movies.stackexchange.com" title="movie an
d tv enthusiasts">Movies & TV</a></li>
<li><a href="//music.stackexchange.com" title="musicians
, students, and enthusiasts">Music: Practice & Theory</a></li>
<li><a href="//cooking.stackexchange.com" title="profess
ional and amateur chefs">Seasoned Advice (cooking)</a></li>
<li><a href="//diy.stackexchange.com" title="contractors
and serious DIYers">Home Improvement</a></li>
<li><a href="//money.stackexchange.com" title="people wh
o want to be financially literate">Personal Finance & Money</a></li>
<li><a href="//academia.stackexchange.com" title="academ
ics and those enrolled in higher education">Academia</a></li>
<li>
<a href="http://stackexchange.com/sites#lifearts" cl
ass="more">
more (8)
</a>
</li>
</ol>
</td>
<td>
<ol>
<li><a href="//english.stackexchange.com" title="linguis
ts, etymologists, and serious English language enthusiasts">English Language &am
p; Usage</a></li>
<li><a href="//skeptics.stackexchange.com" title="scient
ific skepticism">Skeptics</a></li>
<li><a href="//judaism.stackexchange.com" title="those w
ho base their lives on Jewish law and tradition and anyone interested in learnin
g more">Mi Yodeya (Judaism)</a></li>
<li><a href="//travel.stackexchange.com" title="road war
riors and seasoned travelers">Travel</a></li>
<li><a href="//christianity.stackexchange.com" title="co
mmitted Christians, experts in Christianity and those interested in learning mor
e">Christianity</a></li>
<li><a href="//ell.stackexchange.com" title="speakers of
other languages learning English">English Language Learners</a></li>
<li><a href="//japanese.stackexchange.com" title="studen
ts, teachers, and linguists wanting to discuss the finer points of the Japanese
language">Japanese Language</a></li>
<li><a href="//gaming.stackexchange.com" title="passiona
te videogamers on all platforms">Arqade (gaming)</a></li>
<li><a href="//bicycles.stackexchange.com" title="people
who build and repair bicycles, people who train cycling, or commute on bicycles
">Bicycles</a></li>
<li><a href="//rpg.stackexchange.com" title="gamemasters
and players of tabletop, paper-and-pencil role-playing games">Role-playing Game
s</a></li>
<li><a href="//anime.stackexchange.com" title="anime and
manga fans">Anime & Manga</a></li>
<li><a href="//mechanics.stackexchange.com" title="mecha
nics and DIY enthusiast owners of cars, trucks, and motorcycles">Motor Vehicle M
aintenance & Repair</a></li>
<li>
<a href="http://stackexchange.com/sites#culturerecre
ation" class="more">
more (17)
</a>
</li>
</ol>
</td>
<td>
<ol>
<li><a href="//mathoverflow.net" title="professional mat
hematicians">MathOverflow</a></li>
<li><a href="//math.stackexchange.com" title="people stu
dying math at any level and professionals in related fields">Mathematics</a></li
>
<li><a href="//stats.stackexchange.com" title="people in
terested in statistics, machine learning, data analysis, data mining, and data v
isualization">Cross Validated (stats)</a></li>
<li><a href="//cstheory.stackexchange.com" title="theore
tical computer scientists and researchers in related fields">Theoretical Compute
r Science</a></li>
<li><a href="//physics.stackexchange.com" title="active
researchers, academics and students of physics">Physics</a></li>
<li><a href="//chemistry.stackexchange.com" title="scien
tists, academics, teachers and students">Chemistry</a></li>
<li><a href="//biology.stackexchange.com" title="biology
researchers, academics, and students">Biology</a></li>
<li><a href="//cs.stackexchange.com" title="students, re
searchers and practitioners of computer science">Computer Science</a></li>
<li><a href="//philosophy.stackexchange.com" title="thos
e interested in the study of the fundamental nature of knowledge, reality, and e
xistence">Philosophy</a></li>
<li>
<a href="http://stackexchange.com/sites#science" cla
ss="more">
more (3)
</a>
</li>
</ol>
</td>
<td>
<ol>
<li><a href="//meta.stackexchange.com" title="meta-discu
ssion of the Stack Exchange family of Q&A websites">Meta Stack Exchange</a><
/li>
<li><a href="//stackapps.com" title="apps, scripts, and
development with the Stack Exchange API">Stack Apps</a></li>
<li><a href="//area51.stackexchange.com" title="proposin
g new sites in the Stack Exchange network">Area 51</a></li>
<li><a href="https://www.stackoverflowbusiness.com/talen
t">Stack Overflow Talent</a></li>
</ol>
</td>
</tr>
</table>
</div>
</div>
<div id="copyright">
site design / logo © 2017 Stack Exchange Inc; user contribu
tions licensed under <a href="https://creativecommons.org/licenses/by-sa/3.0/" r
el="license">cc by-sa 3.0</a>
with <a href="http://blog.stackoverflow.com/2009/06/attribution-
required/" rel="license">attribution required</a>
</div>
<div id="svnrev">
rev 2017.2.21.25202
</div>
</div>
</div>
<noscript>
<div id="noscript-warning">Stack Overflow works best with JavaScript ena
bled<img src="https://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" cla
ss="dno"></div>
</noscript>
<script>var p = "http", d = "static"; if (document.location.protocol == "https:"
) { p += "s"; d = "engine"; } var z = document.createElement("script"); z.type =
"text/javascript"; z.async = true; z.src = p + "://" + d + ".adzerk.net/ados.js
"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore
(z, s);</script>
<script>
var ados = ados || {};
ados.run = ados.run || [];
ados.run.push(function () {
setTimeout(function () { $("#adzerk-user-match").remove(); }, wi
ndow.AUMIframeDone ? 0 : 2000);
ados_setKeywords('javascript,json,angularjs,text,xmlhttprequest,
x-persona-frontend');; ados_load();
});
</script>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r
].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElem
ent(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.pare
ntNode.insertBefore(a, m);
})(window, document, 'script', 'https://www.google-analytics.com/ana
lytics.js', 'ga');
ga('create', 'UA-5620270-1');
ga('create', 'UA-5620270-59', {name: 'pageData', sampleRate: 5 }
);
ga('set', 'dimension2', '|javascript|json|angularjs|text|xmlhttp
request|');
ga('pageData.set', 'dimension2', '|javascript|json|angularjs|tex
t|xmlhttprequest|');
ga('send', 'pageview');
ga('pageData.send', 'pageview');
var _qevents = _qevents || [],
_comscore = _comscore || [];
(function () {
var ssl='https:'==document.location.protocol,
s=document.getElementsByTagName('script')[0],
qc=document.createElement('script');
qc.async = true;
qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve
.com/quant.js';
s.parentNode.insertBefore(qc, s);
_qevents.push({ qacct: "p-c1rF4kxgLUzNc" });
var sc=document.createElement('script');
sc.async=true;
sc.src=(ssl?'https://sb':'http://b') + '.scorecardresearch.com/b
eacon.js';
s.parentNode.insertBefore(sc, s);
_comscore.push({ c1: "2", c2: "17440561" });
})();
</script>
<script type="text/javascript">
(function(appendChild) {
Node.prototype.appendChild = function() {
var parent = this;
var newNode = arguments[0];
if (parent.nodeName === 'HEAD'
&& newNode
&& newNode.nodeName === 'SCRIPT'
&& newNode.src) {
window.setTimeout(function() {
var result = newNode.src.match(/^https:\/\/maps\
.googleapis\.com\/maps\/api\/place\/js\/(\w+)Service\./i) || [];
var service = result[1];
if (service) {
if (service === 'Autocompletion') service =
2;
else if (service === 'Place') service = 1;
else service = 0;
StackExchange.using('gps', function() {
StackExchange.gps.track('google_maps_pla
ces_api.call', { service: service });
});
}
}, 0);
}
return appendChild.apply(this, arguments);
};
})(Node.prototype.appendChild);
</script>
</body>
</html>