2015-11-28 4 views
1

Мы разрабатываем мобильное приложение с использованием Ionic framework. Вот config.xml и index.html:

config.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<widget id="com.ionicframework.manageyourmatch988887" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>manageyourmatch</name> 
    <description> 
     An Ionic Framework and Cordova project. 
    </description> 
    <author email="[email protected]" href="http://ionicframework.com/"> 
     Ionic Framework Team 
    </author> 
    <content src="index.html"/> 
    <access origin="*"/> 

index.html

 <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> 

Когда мы проводим пост запрос в loginCtrl.js на устройстве мы получаем ошибку 404. Что нам не хватает? Мы разрешили все источники через белый список, используя тег доступа и тег CSP.

loginCtrl - HTTP Post

$http.post(APP_CONFIG.serverUrl, // server url for connetion 
      {action : "login", cell_num : $scope.model.telephone, password : $scope.model.password} // data passed by json post 
      ).then(
      function(response) { // if i recive a response from the server 
       console.log(response.data); 

       if(response.data.status == "success"){ // if the server accepts my login 
        // show toast [native] or an alertPopup [all platforms] 
        if(typeof window.plugins !== "undefined") 
         window.plugins.toast.showLongBottom('Response: ' + response.data.status); 
        else 
         $ionicPopup.alert({title: 'Server response', template: ''+response.data.status}); 

        // test the vibration [HTML5 all platforms] 
        //navigator.vibrate(1000); 

        // Update localStorage 
        localStorage.setItem("telephone", $scope.model.telephone); 
        localStorage.setItem("loggedin", "true"); 
        localStorage.setItem("session_id", response.data.session_id); 

        // Go to homepage 
        $state.go('home.matches'); 
       }else{ 
        // if the login fail due to bad username and password (or something else...) 
        $ionicPopup.alert({ 
          title: 'Error message', 
          template: ''+response.data.error_message 
         }); 
       } 
      }, function(error) { // if something goes wrong 
       console.log(JSON.stringify(error)); 
       $ionicPopup.alert({ 
         title: 'Connection failed', 
         template: 'Error: '+JSON.stringify(error) 
        }); 
      }); 
+0

публикуйте код пожалуйста, я люблю код! (Подсказка, показать только релевантные роли) – Arg0n

+0

Я редактировал, спасибо @ Arg0n –

+0

Вы уверены, что ваш 'APP_CONFIG.serverUrl' содержит правильный URL? – Ashot

ответ

1

Это решило проблему:

<meta http-equiv="Content-Security-Policy" content="default-src *; script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos; *; style-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos; *"> 
Смежные вопросы