Menu icon Foundation
Angular $http.post response is returning html code

I am trying to do a post request with angular but the response is returning the html code of the index file. When i try to run the same code without foundation for apps it works superbly fine but with foundation i don't know what the problem is?

This is the app.js file

(function() {
  'use strict';

  var application = angular.module('application', [
    'ui.router',
    'ngAnimate',

    //foundation
    'foundation',
    'foundation.dynamicRouting',
    'foundation.dynamicRouting.animations'
  ])
    .config(config)
    .run(run)
  ;

  config.$inject = ['$urlRouterProvider', '$locationProvider'];

  function config($urlProvider, $locationProvider) {
    $urlProvider.otherwise('/');

    $locationProvider.html5Mode({
      enabled:false,
      requireBase: false
    });

    $locationProvider.hashPrefix('!');
  };

  function run() {
    FastClick.attach(document.body);
  };

  application.controller('LoginController',['$http',function($http){
    this.user = {};

    this.loginProcess = function(){
      console.log(JSON.stringify(this.user));
      var req = {
          method:'POST',
          url:'templates/home.html',
          headers: {
            'Content-Type':application/JSON
          },
          data:{
            test:'test'
          }
        };
        $http(req).then( function(data){
          console.log(data);
        });
       
      //  var postData = JSON.stringify(this.user);
      //  var config = {method: 'POST', url: '/login.php', data:postData,header:'Content-Type:Text/JSON'};
      //   $http(config)
      //  .success(function(data, status, headers, config) {
      //   console.log(data);
      //    })
      //   .error(function(data, status, headers, config) {
      //   $scope.errorMsg = 'Unable to submit form';
      //   });
      };

  }]);






})();

            

         

angularPHPfoundation for apps

I am trying to do a post request with angular but the response is returning the html code of the index file. When i try to run the same code without foundation for apps it works superbly fine but with foundation i don't know what the problem is?

This is the app.js file

(function() {
  'use strict';

  var application = angular.module('application', [
    'ui.router',
    'ngAnimate',

    //foundation
    'foundation',
    'foundation.dynamicRouting',
    'foundation.dynamicRouting.animations'
  ])
    .config(config)
    .run(run)
  ;

  config.$inject = ['$urlRouterProvider', '$locationProvider'];

  function config($urlProvider, $locationProvider) {
    $urlProvider.otherwise('/');

    $locationProvider.html5Mode({
      enabled:false,
      requireBase: false
    });

    $locationProvider.hashPrefix('!');
  };

  function run() {
    FastClick.attach(document.body);
  };

  application.controller('LoginController',['$http',function($http){
    this.user = {};

    this.loginProcess = function(){
      console.log(JSON.stringify(this.user));
      var req = {
          method:'POST',
          url:'templates/home.html',
          headers: {
            'Content-Type':application/JSON
          },
          data:{
            test:'test'
          }
        };
        $http(req).then( function(data){
          console.log(data);
        });
       
      //  var postData = JSON.stringify(this.user);
      //  var config = {method: 'POST', url: '/login.php', data:postData,header:'Content-Type:Text/JSON'};
      //   $http(config)
      //  .success(function(data, status, headers, config) {
      //   console.log(data);
      //    })
      //   .error(function(data, status, headers, config) {
      //   $scope.errorMsg = 'Unable to submit form';
      //   });
      };

  }]);






})();

            

         

This post has been closed. No new replies can be added.

Chris Oyler over 3 years ago

What exactly are you trying to do, a POST to an html file? Seems like you should be sending the login info to a backend somewhere right?

Rohan Purekar over 3 years ago

@Chris Oyler Yes I was but I was committing a silly mistake of running the php script on npm server. It was running just fine on apache!!