jquery / jquery/jquery-migrate

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

Open
#324 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.1k
Forks
476
Avg merge
10m
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the migration warning in warnings.md and the serialize implementation in src/serialize.js, then compare how $.param handles the traditional flag. Determine whether the accepted resolution is documentation or a jQuery behavior change; done means the chosen path clearly addresses serialize users and is supported by the relevant project checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, tooling
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.