| @@ -124,8 +124,9 @@ | ||
| 124 | 124 | |
| 125 | 125 | function uploadFile() { |
| 126 | 126 | var formData = new FormData(); |
| 127 | 127 | formData.append("action", "optml_replace_file"); |
| 128 | + formData.append("optml_replace_nonce", OMAttachmentEdit.nonce); | |
| 128 | 129 | formData.append("attachment_id", OMAttachmentEdit.attachmentId); |
| 129 | 130 | formData.append("file", $("#optml-replace-file-field")[0].files[0]); |
| 130 | 131 | |
| 131 | 132 | $(".optml-svg-loader").show(); |
| @@ -137,13 +138,14 @@ | ||
| 137 | 138 | processData: false, |
| 138 | 139 | contentType: false, |
| 139 | 140 | success: function(response) { |
| 140 | 141 | $(".optml-svg-loader").hide(); |
| 141 | - if(response.success) { | |
| 142 | + if (response && response.success) { | |
| 142 | 143 | window.location.reload(); |
| 143 | 144 | } else { |
| 145 | + var msg = (response && (response.data || response.message)) || OMAttachmentEdit.i18n.replaceFileError; | |
| 144 | 146 | $(".optml-replace-file-error").removeClass("hidden"); |
| 145 | - $(".optml-replace-file-error").text(response.message); | |
| 147 | + $(".optml-replace-file-error").text(msg); | |
| 146 | 148 | } |
| 147 | 149 | }, |
| 148 | 150 | error: function(response) { |
| 149 | 151 | $(".optml-svg-loader").hide(); |