1

最近、使用していた PhoneGap のバージョンを 0.9.5 から Cordova-1.7.0 に更新しました。アップグレード以来、ブラウザでは正常に動作しますが、Android デバイスからの Ajax 呼び出しを介してサーバーにデータを投稿できなくなりました。

返される jqXHR ステータス コードは 0 です。これは、ネットワーク ワークアップに問題があることを示していますが、問題なくサーバーからデータを取得できます。

0.9.5 と 1.7.0 の間でデータがサーバーに送信される方法に何か変更はありましたか?

私のajax呼び出しは以下の通りです:

    $.ajax({
                type: "POST",
                url: "https://"+serverUrl + "process.php",
                data: {data:passData, key:appKey},
                crossDomain: true,
                cache: false,
                dataType: "text",
                timeout: 5000,
                success: onSuccess,
                error: onError
            });                 

            function onError(jqXHR, exception) {
                if (jqXHR.status === 0) {
                    alert('Not connect.\n Verify Network.');
                } else if (jqXHR.status == 404) {
                    alert('Requested page not found. [404]');
                } else if (jqXHR.status == 500) {
                    alert('Internal Server Error [500].');
                } else if (exception === 'parsererror') {
                    alert('Requested JSON parse failed.');
                } else if (exception === 'timeout') {
                    alert('Time out error.');
                } else if (exception === 'abort') {
                    alert('Ajax request aborted.');
                } else {
                    alert('Uncaught Error.\n' + jqXHR.responseText);
                }

                showAlert("Failed to transmit, saved for re-transmital.", "Alert", 1);
}

function onSuccess(data){
 alert('successfully transmitted');
}

更新 "async: false" を呼び出しに追加し、機能しました。以下の更新されたコードを参照してください。

$.ajax({
                type: "POST",
                url: "https://"+serverUrl + "process.php",
                data: {data:passData, key:appKey},
                crossDomain: true,
                cache: false,
async: false,
                dataType: "text",
                timeout: 5000,
                success: onSuccess,
                error: onError
            });   
4

0 に答える 0