错误http.get angular

时间:2015-10-11 20:16:21

标签: angularjs http

我有一个让我发疯的问题。它是关于具有离子/角度的移动应用程序,需要您的帮助:

在我的代码中,我发出一个http请求来获取这样的数组:

{"Exist": 0}

我确信运行此请求的服务器已运行并收到请求,因为在记录器中我看到了请求。

我已经写了一些日志消息,以查看我的应用程序出错的位置,并始终停止.error部分。

js

angular.module('starter.controllers', [])

.factory('validaEmail', function($http) {

    return {
        existeEmail: function($correo){
            console.log("Dentro de validaEmail");
            $http.get("http://www.promozzapp.com/php/validaUser.php?email=" +$correo)
                .success(function(valor1, valor2) {
                    console.log("SUCESS ");
                    window.alert("SUCESS");

                })
                .error(function (data, status, headers, config){
                    console.log("ERROR - "+data+" - "+status);
                    window.alert("ERRORR" + data +  " - "  +status + " - H: " +headers);

                })
                .then(function(response) {
                    console.log("**** THEN **** " );
                });
        }   
    };
})

index.html

<html>
  <head> 
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' http://www.promozzapp.com  'unsafe-eval' 'unsafe-inline';">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

1 个答案:

答案 0 :(得分:0)

首先,尝试在浏览器中输入此网址:http://www.promozzapp.com/php/validaUser.php?email=test@example.com

您将看到它返回无效的JSON字符串。

其次,此网址返回text/html响应,而不是json

您的错误位于validaUser.php文件

中的后端代码中