2016-01-13 70 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

我不能添加