使用$ http POST方法更新textarea

时间:2016-01-13 15:26:57

标签: javascript angularjs

我在http://language.cs.usm.my/synthesis/read.php的表单中有一个textarea。此URL是第三方网页,如何将我的内容发布到该URL并替换现有的textarea内容。

到目前为止,我尝试使用下面的方法将我的内容发布到网址,但似乎没有这样做。

$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!");
    })
}

有人对此提出建议吗?提前谢谢。

2 个答案:

答案 0 :(得分:1)

这应该更好:

$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!");
  });

在你看来:

<textarea ng-model="myTextAreaValue" /> 

PS:别忘了将textarea包装到你向我们展示的控制器中。

答案 1 :(得分:0)

由于我无法将POST数据直接发送到服务器,所以我使用ajax方法来解决这个问题。

$.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
        });
相关问题