SSブログ

[Note] iPad で $.ajax の失敗 - Failure of $.ajax in iPad [iOS]

jQuery の $.ajax を使っている Web システムで、iPad だと特定の操作で特定のエラーメッセージが出現することが発覚しました。

I found that the Web system which used $.ajax of jQuery output specific error message by specific operation.

メッセージ文字列から追跡したところ、$.ajax を自作の JavaScript オブジェクトで隠ぺいし、エラーハンドラー内で決められた文字列を alert するようハード コーディングされていたため、この隠ぺいされた独自の Ajax が失敗すると、冒頭の特定のエラーメッセージが出ていたことがわかりました。

I traced the problem by the message string, then I found the concealed someone's own making code including $.ajax, and the code had a hardcoded error handler with "alert", so if the $.ajax failed the error handler output above specific error message.

また、ユーザーが値を入力できるほとんどのエレメントでフォーカス アウト系イベントをトラップし、無条件でこの独自の Ajax を実行していました。

And, most editable elements' focus out events were trapped to call the concealed own Ajax process unconditionally.

この時点で、こういう作り自体がナンセンスなんだけど。

I was sure that such a process is nothing but nonsense.

では、なぜ特定の操作で必ず $.ajax がエラーとなるのか。

Then, why did this system fail invariably with $.ajax by specific operation?

追調査した結果、$.ajax のリクエスト処理中にページのアンロードがかかると、xmlHttpRequest が status = 0 で失敗していました。

With more trace, if page unload occurred in the period of the $.ajax, the $.ajax failed with xmlHttpRequest status = 0.

ページのアンロードを誘発する遷移に関する操作が、この現象のトリガーでした。

Operation about the page transition to cause the page unload was the trigger of this problem.

ネットで調べてみたところ、ページのアンロード時に status = 0 になる現象は、特定のブラウザーと jQuery のバージョンの組み合わせで起きるようです(2.0.0 以降では起きないとか???)。

According to articles in the net, the problem that the $.ajax is fail with status = 0 at the time of page unload will be happened by the specific combination of the browser and the jQuery version(this problem fixed with 2.0.0?).

手元の環境では、iOS 6.x および iOS 7.0.x と、jQuery 1.8.2 の組み合わせで問題が起きていました。

In my case, the problem occurred by a combination of jQuery 1.8.2 and iOS 6.x or iOS 7.0.x.

とはいえ、以前記事にした通り、iPad では beforeunload を捕まえられないし、代わりのイベントの pagehide も発生条件が一定でないので、$.ajax を中断するにもキッカケがありません。

But, as I took an article the other day, iPad Safari Mobile doesn't fire beforeunload event, and the outbreak condition of pagehide event is not constant, so there is no opportunity to abort $.ajax.

本件のケースでは納期が迫っていたため、エラーメッセージの出力を抑制するフラグを仕込んで逃げました。

In this case, there was no enough time by the deadline, I evaded this problem by creating the flag which controlled the output of the error message.

ライブラリにはバグがあると思えということと、内部処理とプレゼンテーション処理は分離しろ、ということですね。

A library has a bug, and the processes should be separated in internal and presentation. 


nice!(2)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 2

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。