やあみんな、この問題がたくさん投稿されていることは知っていますが、何も役に立たないので、この質問をしています.質問は、phpに同期リクエストを送信する問題に直面しています. ここにリクエストを送信している私のモデル関数があります。
State.pushData = function () {
$http({
method: 'POST',
url: 'pushData.php?action=pushdata',
data: {'status': 'push', 'email' : State.campemail},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(response){
if(response.error){
console.log(response.error);
return;
}
State.getCartData();
State.selectedItems = [],
});
}
この pushData 関数は、定義された URL にポスト リクエストを送信します。応答をフェッチします。書かれたコードは、最初に送信されたリクエストの成功時に「State.getCartData()」関数を実行することを想定しています。しかし、これはこのようには機能していません。両方のリクエストが一度に実行されます。$http を .post とメソッドで試しましたが、結果は同じでした。このような
State.pushData = function () {
$http.post('pushData.php?action=pushdata',
{'status': 'push', 'email' : State.campemail}
).then(function(response){
if(response.error){
console.log(response.error);
return;
}
State.getCartData();
State.selectedItems = [],
});
}
getCartData() 関数が実行された後に pushQuote リクエストが完了すると、非同期でリクエストを送信したいと考えています。これについてあなたの経験を共有してください。前もって感謝します。