上传文件时AngularJS错误

时间:2016-05-24 15:08:29

标签: angularjs http file-upload

此代码:

<?php
session_start();
require_once './include/db_connection.php';
require_once './functions/functions.php';



    $Username = $_POST['Username'];
    $Password = $_POST['Password'];
    $Remember = $_POST['Remember'];




  $sql = "select * from signup where username = '$Username' and password = '$Password'";
  $result = mysqli_query($link, $sql);

  if(mysqli_num_rows($result)>0)

  {
    if(!empty($_POST['Remember']))
    {
        setcookie("username", $Username,time()+ (10 * 365 * 24 * 60 * 60));
        setcookie("pass", $Password,time()+ (10 * 365 * 24 * 60 * 60));

    }
    else
    {
        //if without clicked on checkbox the cookie still exist then destroy it 
        if(isset($_POST['Username']))
        {
            setcookie("username", "", time()-3600);

        }

        if(isset($_POST['Password']))
        {
            setcookie("username", "", time()-3600);
        }


        }

      echo 'true';
      $_SESSION['username'] = $Username;
  }
  else
  {
      echo "false";
  }

}]);

产生此错误:&#34;容器没有处理POST&#34;

的方法
App.service('fileUpload', ['$http', function($http) {
   this.uploadFileToUrl = function(file, uploadUrl) {

    console.log("inside upload file service js ");

    var fd = new FormData();
    fd.append('file', file);

    $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: {
                'Content-Type': undefined
            }
        })
        .success(function(response) {

            console.log("file uploaded sucessfully " + response);

        })
        .error(function(error) {

            console.log("Error while uploading file " + JSON.stringify(error));
        });
}

0 个答案:

没有答案