我有一個頁面,通過角$ http.post(..) 發送數據到ASPNET MVC頁面,當調用完成時我必須提交表單。角度事件成功時提交表單它打開彈出
基本上我執行以下操作:
<html ng-app>
<body data-ng-controller="testController">
<form id="Checkpay" name="Checkpay" style="margin: 0" method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="_blank" class="ng-pristine ng-valid">
<input type="hidden" name="quantita" id="qtytext" value="0">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="Le Spose di Nika">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="cancel_return" id="cancel_return" value="">
<input type="hidden" name="return" id="return" value="">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" id="H_amount" name="amount" value="719.80">
<input type="hidden" id="H_first_name" name="first_name">
<input type="hidden" id="H_address1" name="address1">
<input type="hidden" id="H_city" name="city">
<input type="hidden" id="H_state" name="state">
<input type="hidden" id="H_zip" name="zip">
<input type="hidden" id="H_email" name="email">
<input type="hidden" id="Country" name="country">
<input type="hidden" id="charset" name="charset" value="utf8">
<input type="hidden" id="rm" name="rm" value="2">
<input type="hidden" id="notify_url" name="notify_url" value="">
<input id="Submit1" type="submit" value="submit_post" />
</form>
<input id="Submit2" type="button" data-ng-click='pay()' value="js_post" />
</body>
</html>
<script src="http://localhost:27433/Scripts/jquery-1.7.1.min.js"></script>
<script src="http://localhost:27433/Scripts/jquery-ui-1.8.20.min.js"></script>
<script src="http://localhost:27433/Scripts/angular.js"></script>
<script>
function test() {
}
function testController($scope, $http) {
var URL = "http://backend.MYSITE.com/";
$scope.payTest = function() {
var PAYPAL_URL_RELEASE = "https://www.paypal.com/cgi-bin/webscr";
var PAYPAL_URL_SANDBOX = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$('#cancel_return').val(URL + '/ErrorPay');
$('#return').val(URL + '/Success');
$('#notify_url').val(URL + '/PayPalReceiverIPN.ashx?idOrder=');
document.forms["Checkpay"].action = PAYPAL_URL_RELEASE;
document.forms["Checkpay"].submit();
console.log('paytest is executed!');
}
$scope.pay = function() {
////$.post( URL + "/Order/Create", JSON.stringify({ newOrder: 1 }))
//// .success(function (datdata, status, headers, configa) {
//// console.log(' $.post success');
//// $scope.payTest();
//// }).error(function (data, status, headers, config) {
//// console.log(' $.post failure');
//// });
$http.post(
URL + "/Order/Create", JSON.stringify({ newOrder: 1 })
).success(function (datdata, status, headers, configa) {
console.log('http success');
$scope.payTest();
}).error(function (data, status, headers, config) {
console.log('http failure');
});
}
}
</script>
當我做document.forms [ 「Checkpay」]提交();我方面有一個重定向 到我的表單的屬性動作的頁面,而不是我會彈出一個頁面,我會重定向。
我試圖把函數payTest()從「成功」,它的作品,然後我認爲這個問題是 對象$ http(或ajax)如何處理「成功」代表。
問題是:無論如何,當$ http.post(....)完成調用時,對頁面進行重定向?
謝謝
嗨米歇爾, 我已經試過你的建議,但不改變角度$ HTTP使用異步請求。 該函數可以按照我所發佈的建議調用。 我認爲問題出在委託成功/錯誤, ,但我不能得到原因: - \ –
我rewote $ http調用,我把一些日誌消息,所以你可以檢查看看會發生什麼(或不) – Michiel
我剛剛嘗試過,調用繼續成功,所以任何錯誤發生, 我希望我解釋好我的問題,我試圖讓它更清晰, 我沒有得到任何錯誤,我只是提交我的表單,並得到一個重定向進入操作屬性的頁面。 的問題是,我得到一個彈出時,我做的代碼,而不是 提交獲得頁面的重定向.. 對不起ID我做了一個容易混淆的問題 –