@@ -128,38 +128,40 @@ jQuery(function($) {
128
128
jQuery ( ".ppom-meta-save-notice" ) . html ( '<img src="' + ppom_vars . loader + '">' ) . show ( ) ;
129
129
130
130
$ ( '.ppom-unsave-data' ) . remove ( ) ;
131
- const data = $ ( this ) . serializeJSON ( ) ;
132
-
133
- const fieldsOrder = Array ( ...document . querySelectorAll ( '.ui-sortable-handle[id^="ppom_sort_id_"]' ) )
134
- . map ( node => node . id . replace ( 'ppom_sort_id_' , '' ) ) ; // ['2', '3']
135
- data . ppom = fieldsOrder . map ( fieldId => data . ppom [ fieldId ] ) ;
131
+
132
+ const formData = new FormData ( ) ;
133
+ const ppomFields = new URLSearchParams ( ) ;
136
134
137
- data . ppom = JSON . stringify ( data . ppom ) ;
138
-
139
- // Send the JSON data via POST request
140
- $ . ajax ( {
141
- url : ajaxurl ,
142
- data : data , // Send as regular object (no need to stringify)
143
- type : 'POST' ,
144
- success : function ( resp ) {
145
-
146
- const bg_color = resp . status == 'success' ? '#4e694859' : '#ee8b94' ;
147
- jQuery ( ".ppom-meta-save-notice" ) . html ( resp . message ) . css ( { 'background-color' : bg_color , 'padding' : '8px' , 'border-left' : '5px solid #008c00' } ) ;
148
- if ( resp . status == 'success' ) {
149
- if ( resp . redirect_to != '' ) {
150
- window . location = resp . redirect_to ;
151
- }
152
- else {
153
- window . location . reload ( true ) ;
154
- }
155
- }
156
- } ,
157
- error : function ( ) {
158
- // Handle error
159
- jQuery ( ".ppom-meta-save-notice" ) . html ( "An error occurred. Please try again." ) . css ( { 'background-color' : '#ee8b94' , 'padding' : '8px' , 'border-left' : '5px solid #c00' } ) ;
135
+ // NOTE: since the request is to big for small values of `max_input_vars`, we will send the PPOM fields as a single string.
136
+ ( new FormData ( this ) ) . forEach ( ( value , key ) => {
137
+ if ( key . startsWith ( 'ppom[' ) && typeof value === 'string' ) {
138
+ ppomFields . append ( key , value ) ;
139
+ } else {
140
+ formData . append ( key , value ) ;
160
141
}
161
142
} ) ;
162
143
144
+ formData . append ( 'ppom' , ppomFields . toString ( ) ) ;
145
+
146
+ fetch ( ajaxurl , {
147
+ method : 'POST' ,
148
+ body : formData
149
+ } )
150
+ . then ( response => response . json ( ) )
151
+ . then ( resp => {
152
+ const bg_color = resp . status == 'success' ? '#4e694859' : '#ee8b94' ;
153
+ jQuery ( ".ppom-meta-save-notice" ) . html ( resp . message ) . css ( { 'background-color' : bg_color , 'padding' : '8px' , 'border-left' : '5px solid #008c00' } ) ;
154
+ if ( resp . status == 'success' ) {
155
+ if ( resp . redirect_to != '' ) {
156
+ window . location = resp . redirect_to ;
157
+ } else {
158
+ window . location . reload ( ) ;
159
+ }
160
+ }
161
+ } )
162
+ . catch ( ( ) => {
163
+ jQuery ( ".ppom-meta-save-notice" ) . html ( "An error occurred. Please try again." ) . css ( { 'background-color' : '#ee8b94' , 'padding' : '8px' , 'border-left' : '5px solid #c00' } ) ;
164
+ } ) ;
163
165
} ) ;
164
166
165
167
0 commit comments