1

We are developing a mobile app using the Ionic framework. Here are the config.xml and index.html files:

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="hi@ionicframework" 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'">

When we perform a post request in the loginCtrl.js on the device we get the 404 error. What are we missing? We allowed all sources through the whitelist using the access tag and the CSP tag.

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)
                    });
            });
8
  • Post more code please, i love code! (Hint, show only relevant parts) Commented Nov 28, 2015 at 19:15
  • I edited, thank you @Arg0n Commented Nov 28, 2015 at 19:24
  • Are you sure that your APP_CONFIG.serverUrl contains correct url ? Commented Nov 28, 2015 at 19:52
  • Hi @Ashot, yes I checked and the url is correct Commented Nov 28, 2015 at 19:53
  • 1
    Where is your whitelist plugin? Commented Nov 29, 2015 at 3:19

1 Answer 1

1

This solved the problem:

<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; *">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.