Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

Connection to a remote server



  • i am trying to use the code below, to connect to my remote server…and i am expecting it to send the fname and the lname with the url altogether…since they are my textfield.
    after submitting my form, it’s only the url that is always been sent…(since i am always seeing it in my log…)how can i solve this

    $http.post(“url”, {‘fname’:$scope.fname, ‘lname’:$scope.lname})
    .success(function(data, status, headers, config) {…}



  • Hm… Only with this amount of information it’s a little hard to determine the problem.

    There are a couple of things which I can think of which might be of some use though:

    1. Make sure that you’re checking the log on the server and not in the browser
    2. Currently you’re saying that you’re calling this when you submit the form - maybe you forgot to prevent the default behaviour.
    3. You could try just to make a simple request without the form (just write $http.post('url', {a: 1}) when you click a div or something similar) and see if it works.

    If even the third one doesn’t work I would think that there might be a problem with your server (in that case try to test it with a simple http request :D without any other code).



  • this is my script

     <script>
      var app = angular.module('myapp', [])
      app.controller('empcontroller', function($scope, $http){
      $scope.insertdata=function(){
    //the fname and the lname are the ones i want to send together with the url
      $http.post("url", {'fname':$scope.fname, 'lname':$scope.lname})
      .success(function(data, status, headers, config) {
            console.log(data);
            if ( data.trim() === 'correct') {
              window.location.href = 'homes.html';
            } else {
              $scope.errorMsg = "Login not correct";
            }
          })
          .error(function(data, status, headers, config) {
            $scope.errorMsg = 'Unable to submit form';
          })
      }});</script>
    

    //i already tried the url with the data i want to send…and i am getting my result…
    let me say, i want to post into this url (tutorial.com/Project/mob_req.php?op=uservalidate)
    if i should type that url alone, i am going to get user not registered…but, if i should now do it in this way (tutorial.com/Project/mob_req.php?op=uservalidate&fname=user&lname=pass)…if i should type that into the url…i will get a 1…that’s if the user has been registered already…
    so, what i want to do in this respect is to send something like that…to that URL…i was able to accomplish this task…using my java…so, i want to rebuild the application using onsen…and i am kind of stocked up

    i already tried $http.post, and $http.jsonp…they are both giving me same reply which is…invalid user



  • I have been able to solve it :grinning: :smile: :relaxed: …the problem is this, i was supposed to transform my data from object to URLPARAMS and not to JSON string…
    so, instead of the $http.post i used up there…
    i did something like this

    $http({
        method: 'POST',
        url: "url",
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        transformRequest: function(obj) {
            var str = [];
            for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            return str.join("&");
        },
        data: {username: $scope.fname, pswd: $scope.lname}
    })
      .success(function(data, status, headers, config) {...
          })
    

    and it worked well…



  • Oh nice, good job!