douwen3198 2015-11-08 13:09
浏览 48

Angular.js MySQL JSON到$ scope

I have a problem with getting data from MySQL database to angular $scope.

Here is my app.js

var mxscope = angular.module('mxscope', ['ui.router']);

mxscope.config(function($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/home');

$stateProvider    
    .state('stock', {
        url: '/home',
        templateUrl: 'views/stock.html',
        controller: 'stockController'
    })

});

mxscope.controller('stockController', function($scope, $http) {

$http.get('lib/getStockProducts.php')

    .success(function(data) {
        console.log(data);
        $scope.products = data;
    })
    .error(function(){
        console.log('error whatever');
    })
});

If You look on the particular controllers there is one with http.get request And it doesn't seem to work: but I've found some strange behavior when testing it. The whole app is wrapped into .Electron app, and when I try the app the http.get request returns the code inside .php file.. Like so:

getStockProducts.php

<?php
include 'db.php';
$query="select * from sc_products";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

$arr = array();

if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $arr[] = $row;
    }
}
echo $json_response = json_encode($arr);
?>

with an dupes error :

Error: [ngRepeat:dupes] http://errors.angularjs.org/1.4.7/ngRepeat/dupes?p0=product%20in%20products&p1=string%3Ap&p2=p

But when I fire up the same app in browser window it works like charm, but it still returns duplicate result.

Any help ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题