クロスドメイン AJAX POST リクエストは、携帯電話のブラウザーを含む Web ブラウザーでは完全に正常に機能しますが、使用して構築されたネイティブ アプリケーションでは機能しません。Phonegap
ユーザーがログイン資格情報を入力する必要があるログインフォームを作成しました。その後、heroku でホストされているサーバーによって検証され、{"success":true}有効な資格情報が入力された場合は json が返されます。
私のAjaxスクリプト:
$.ajax({
   type: "POST",
   url: "http://domain.com/public/auth/app-login",
   contentType: "application/x-www-form-urlencoded; charset=utf-8",
   dataType: "json",
   data: {identity: <username from form>, password: <password from form>},
   crossDomain: true,
   cache: false,
   success: function(data) {
       obj = JSON.parse(data);
       if (obj && obj.success === true) {
          window.location.href = 'home.html';
       }
   },
   error: function(e) {
       alert('Error: ' + e.message);
   }
});
この問題を解決するための手順:
- ドメインのホワイトリスト登録- config.xml
<access origin="http://domain.com/public/auth/app-login" />
<access origin="*" />
- クロスドメインを許可するようにjQueryに指示する
$.support.cors = true;
また
jQuery.support.cors = true;
- キャッシュを無効にするcache: false
どんな助けでも大歓迎です。