2016-01-13 109 views
-1

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

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

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

任何人对此有何建议?预先感谢。

+0

使用dataType:'jsonp'在构建参数时执行跨站点请求。 – siimsoni

+1

如果[CORS已启用](http://stackoverflow.com/questions/25845203/understanding-cors),则无法发布到其他域。 [跨域后](http://stackoverflow.com/a/2699351/2246862) –

回答

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 
     }); 
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到您向我们展示了控制器。

+0

我不能添加