-1

I have a textarea in the form on http://language.cs.usm.my/synthesis/read.php. This URL is third party web page, how can i POST my content to that URL and replace the existing textarea content.

So far, i try to use the method below post my content to the URL but it seems failed to do so.

$scope.AudioCont = function(){
    var req = $http({
             method: 'POST',
             url: 'http://language.cs.usm.my/synthesis/read.php',
             data:{
                 test:"Nama saya ialah Ali"
             }
    })
    .then(
        function (response) {
        alert("The data has been posted");
        console.log(response);
    },
    function () {
        alert("Failed to post!");
    })
}

Anyone have suggestion on this? Thank in advance.

Alex
  • 3
  • 3
  • Use dataType: 'jsonp' when building the argument to do cross site requests. – ksiimson Jan 13 '16 at 15:30
  • 1
    You can't post to another domain without [CORS enabled](http://stackoverflow.com/questions/25845203/understanding-cors). [cross domain post](http://stackoverflow.com/a/2699351/2246862) – Henry Zou Jan 13 '16 at 15:35

2 Answers2

1

This should be better :

$http.post('/synthesis/read.php', {test:"Nama saya ialah Ali"})
.then(function(response) {
    alert("The data has been posted");
    //$('#myTextArea').val(response); //updating text in the textarea
    $scope.myTextAreaValue = response.data;
    console.log(response);
  },function() {
    alert("Failed to post!");
  });

And in your view :

<textarea ng-model="myTextAreaValue" /> 

PS : do not forget to wrap your textarea into the controller that you showed us.

Deblaton Jean-Philippe
  • 11,188
  • 3
  • 49
  • 66
0

Since I can't direct POST data to the server, so i use ajax method to solve this problem.

$.ajax({
        type: 'POST',
        url: 'your url',
        data: {'submit': 'submit', 'malayText' : "data that wish to POST"}, // you can use as much as data you want to send,
        dataType: 'JSON' // so you can use the json_encode php function
        });
Alex
  • 3
  • 3