cordova(离子)android / php应用程序出错

I'm making a android application with ionic/cordova in client side and php in the server side, but every time I test it I get this error

----------------------------------------------------------------------------

Resource interpreted as Script but transferred with MIME type text/html: "http://restaurent.eb2a.com/app/test.php?callback=angular.callbacks._0". Uncaught SyntaxError: Unexpected token <

failure

undefined

404

----

----------------------------------------------------------------------------

This is my index.html

<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="utf-8">
  <script src="js/angular.min.js"></script>
</head>
<body ng-app="myApp">
  <div ng-controller="myCtrl">
    <button ng-click="clicked($event)">Click me</button>
  </div>

  <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope, $http) {
      $scope.clicked = function($event) {
        var url = "http://restaurent.eb2a.com/app/test.php?callback=JSON_CALLBACK";
        $http.jsonp(url).success(function(data) {
          //console.log("success");
          if (data['reponse'] == 'true') {
            console.log("success");
            console.log(data);
            console.log("----");
          }
        }).error(function(data, status) {
          console.log("failure");
          console.log(data);
          console.log(status);
          console.log("----");
        });
      };
    });
  </script>
</body>

</html>

And this is my test.php

<?php

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
header('Access-Control-Allow-Credentials: true');
header('Content-Type: application/json');
echo $_GET['callback'] ."({'reponse': 'true'})";
?>

Note: whene I test this same code with browser, it work fine.

duanqi5333
duanqi5333 纠正你的问题文本:)
接近 5 年之前 回复
duanliaouu965826
duanliaouu965826 不是餐馆,imean测试,对不起
接近 5 年之前 回复
dsam70528
dsam70528 你确定你在调用restaurant.php而不是test.php吗?
接近 5 年之前 回复

1个回答



您的请求中可能需要配置:
angular http-jsonp </ p>

像这样:</ p>

  header:{
'Content-Type':'application / json'
}
</ code> </ pre>
</ div>

展开原文

原文

maybe you need a config in your Request: angular http-jsonp

Like this:

headers: {
    'Content-Type': 'application/json'
  }

douxie2029
douxie2029 已经做过标题('Content-Type:application / json');
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问