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

Đang mở
#324 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
30/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
frontend, tooling

Hướng nghiên cứu

Bắt đầu với cảnh báo di chuyển trong warnings.md và phần triển khai serialize trong src/serialize.js, sau đó so sánh cách $.param xử lý cờ traditional. Xác định xem hướng giải quyết được chấp nhận là thay đổi tài liệu hay thay đổi hành vi của jQuery; công việc được xem là hoàn tất khi hướng đã chọn giải quyết rõ ràng vấn đề của người dùng serialize và được các kiểm tra liên quan của dự án hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
JavaScript
Star
2.1k
Fork
477
Merge trung bình
20 giờ 48 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của jquery/jquery-migrate

Tất cả issue của jquery/jquery-migrate

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.