@@ -128,38 +128,26 @@ 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 ] ) ;
136
-
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
- }
131
+
132
+ fetch ( ajaxurl , {
133
+ method : 'POST' ,
134
+ body : new FormData ( this )
135
+ } )
136
+ . then ( response => response . json ( ) )
137
+ . then ( resp => {
138
+ const bg_color = resp . status == 'success' ? '#4e694859' : '#ee8b94' ;
139
+ jQuery ( ".ppom-meta-save-notice" ) . html ( resp . message ) . css ( { 'background-color' : bg_color , 'padding' : '8px' , 'border-left' : '5px solid #008c00' } ) ;
140
+ if ( resp . status == 'success' ) {
141
+ if ( resp . redirect_to != '' ) {
142
+ window . location = resp . redirect_to ;
143
+ } else {
144
+ window . location . reload ( ) ;
155
145
}
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' } ) ;
160
146
}
147
+ } )
148
+ . catch ( ( ) => {
149
+ jQuery ( ".ppom-meta-save-notice" ) . html ( "An error occurred. Please try again." ) . css ( { 'background-color' : '#ee8b94' , 'padding' : '8px' , 'border-left' : '5px solid #c00' } ) ;
161
150
} ) ;
162
-
163
151
} ) ;
164
152
165
153
0 commit comments