Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:33:55+00:00 2026-06-17T09:33:55+00:00

Very new to angular – just exploring at the moment. Would be very grateful

  • 0

Very new to angular – just exploring at the moment. Would be very grateful for a pointer or two as to where I am going wring here – TIA

What I would like to do is take data from a mysql select query and return it into an html page, using json and then have angular to display it.
Have succeeded in returning the data using JSON_encode – ran it through jsonlint and it has come back as fine. For testing, I then took this string and created a text file, and ran it through the angular file – it works fine.

If I call the data direct from the php file it fails, but if I call the data from a static text file (with what appears to be the same output as the php data) it works.

I am sending the data with echo – is this correct?

$json=json_encode($main_arr); 
echo $json;

json output:

[{"custcode":"CMZIG001","cli":"0020\/1"},{"custcode":"CMZIG002","cli":"0020\/2"},{"custcode":"CMZIG003","cli":"0020\/3"},{"custcode":"999","cli":"002871365801"},{"custcode":"CMSLE001","cli":"0030"},{"custcode":"CMNIC001","cli":"0034"},{"custcode":"CMLIF001","cli":"0047"},{"custcode":"CMTON01101","cli":"0087\/1"},{"custcode":"CMTON01102","cli":"0087\/2"},{"custcode":"CMTRE001","cli":"0090"}]

Text file contents:

[{"custcode":"CMZIG001","cli":"0020\/1"},{"custcode":"CMZIG002","cli":"0020\/2"},{"custcode":"CMZIG003","cli":"0020\/3"},{"custcode":"999","cli":"002871365801"},{"custcode":"CMSLE001","cli":"0030"},{"custcode":"CMNIC001","cli":"0034"},{"custcode":"CMLIF001","cli":"0047"},{"custcode":"CMTON01101","cli":"0087\/1"},{"custcode":"CMTON01102","cli":"0087\/2"},{"custcode":"CMTRE001","cli":"0090"}] 

In response to comments:

OK – I had hoped not to bore you with my code. An html file as below (I will try to format it correctly)

<!doctype html>
<html ng-app="App">
<head>
    <meta charset="utf-8">
    <title>CLIs http</title>
    <link rel="stylesheet" href="style.css">
    <script>document.write("<base href=\"" + document.location + "\" />");</script>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js">      
</script>
    <script src="app.js"></script>

</head>

<body ng-controller="TodoCtrl">
    <ul>
        <li ng-repeat="cli in cli">
            {{cli.custcode}} - <em>{{cli.cli}}</em>                
        </li>
    </ul>

</body>
</html>

app.js – currently set to call a php file on my server

var App = angular.module('App', []); 

App.controller('TodoCtrl', function($scope, $http) {

 $http.get('http://localhost/t5/clis.json')
 //$http.get('njs.json') 

.then(function(res){

$scope.cli = res.data;

});

});

clis.json (the php file on my server)

$con = mysql_connect("localhost","root","password");
if (!$con)
  {
die('Could not connect: ' . mysql_error());
}
$db='mutuxf';
mysql_select_db($db, $con);

$result = mysql_query("SELECT custcode, cli  FROM clis limit 10");


 while($row = mysql_fetch_assoc($result))
{   
foreach($row as $key => $value)
{    $arr[$key] = $value; }

$main_arr[] = $arr;
}
 $json=json_encode($main_arr); 
 echo $json;


?> 

When I use the php file to raise the data, I merely get a bulleted list with no text, but when I use the text file (njs.json) the page works correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:33:56+00:00Added an answer on June 17, 2026 at 9:33 am

    firstly, i would recommend switching from .then() to .success() and .error(), so you know if all is going well.

    other than that, since the question information is lacking and quite general, i would bet that the json fetching and building part on the server is the problem.
    maybe this link would help

    the way they fetch it:

    $data = file_get_contents("php://input");
    $objData = json_decode($data);
    

    pay attention to the comment, it might be key here:

    // The request is a JSON request.
    // We must read the input.
    // $_POST or $_GET will not work!
    

    in general- if you have the option to add or switch framework on the backend, i would recommend symfony/django for php or switch to RoR with RABL/GON to generate the jsons. it’s so much easier and intuitive.
    hope it helps, it’s been a while since i used vanilla php.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very new to C++ and Cocos2d-x but I was just toying around with CCArray
Very new to javascript and html-type stuff. I wanted to just make a quick
Very new mobile developer here... I am trying to retrieve a list of tweets
Very new to android and have just done a database tutorial and run into
very new to javascript, but any help to get me started would be appreciated.
Very new to JS here. When I write PHP I have no problem assigning
Very new to Iphone development here, I have a project which is successfully building
Very new to membership provider and just implemented on my new web site. I
Im very new to javascript and jquery so please bear with me. Here's my
very new to writing Java, so am grateful for any help I can get.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.