Migrate error from within jQuery when using $.serialize with $.ajaxSettings.traditional

オープン
#324 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
30/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
frontend, tooling

調査の方向性

warnings.md の移行警告と src/serialize.js の serialize 実装から始め、次に $.param が traditional フラグをどのように処理するかを比較します。受け入れられた解決策がドキュメントの変更なのか、jQuery の動作変更なのかを判断します。選択した方針が serialize の利用者に明確に対応し、関連するプロジェクトのチェックによって裏付けられていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

My site uses $.ajaxSettings.traditional = true, and we're working on upgrading to jQuery 3 now. The migrate script is showing a warning when I use $('form').serialize() because the implementation within jQuery uses param without checking the value of the traditional flag.

jQuery.fn.extend( {
	serialize: function() {
		return jQuery.param( this.serializeArray() );
	},
	...
})

(from serialize.js line 99-ish)

I was able to fix the warning by replacing $('form').serialize() with $.param( $('form').serializeArray() , $.ajaxSettings.traditional ), but I'm wondering for future users if it wouldn't be helpful to either:

  • Update the migrate documentation to suggest this fix (other programmers might have a hard time understanding what the problem is, since the migrate documentation doesn't reference serialize anywhere; I was confused for a bit before I realized that the offending code was within jQuery), or
  • modify the jQuery source to explicitly use the traditional flag in the serialize implementation:
     jQuery.fn.extend( {
     	serialize: function() {
     		return jQuery.param( this.serializeArray(), jQuery.ajaxSettings.traditional );
     	},
     	...
     })
    

Happy to PR if either of those is desirable.

主要言語
JavaScript
スター
2.1k
フォーク
477
平均マージ
20時間 48分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jquery/jquery-migrate のほかの issue

jquery/jquery-migrate の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。